I'd use an element with requestAction.  You can find a tutorial on how
to use them here: 
http://bakery.cakephp.org/articles/view/creating-reusable-elements-with-requestaction

Hope that helps.
hydra12

On Oct 26, 2:34 pm, Adam Risser <[EMAIL PROTECTED]> wrote:
> I have a section in my default layout (default.ctp) called "Recent
> Posts".  The posts are stored in my database.  Currently, each method
> in my posts controller includes the following code.
>
> # code snippet 1
> $fields = array('id', 'title');
> $this->set('data_for_layout', $this->Post->findAll(null, $fields,
> null, 5));
>
> Then I use this in my layout (default.ctp) to print out the posts
>
> #layout code snippet.
> foreach($data_for_layout as $post)
> {
>    echo '<li><a href="/posts/view/' . $post['Post']['id']  . '">'.
> $post['Post']['title'] . "</a></li>\n";
>
> }
>
> My problem is that I have to include the top code snippet in each
> method to make it work this way, which seems wrong.  I have been
> trying to find a better way to do this in the manual, but am coming up
> empty.  Am I supposed to use elements or helpers to do this? Can I tie
> those to the database somehow?  Any help would be greatly appreciated
> since I am new to cakePHP! Thanks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to