tags:

views:

383

answers:

2

In my CakePHP application layout I have a section for latest posts that needs to pull from a database. How would I tell it to render a partial so I can pull the latest posts? Sorry if this is a simple question, I just started CakePHP tonight.

A: 

You can use elements to render a "mini view" of something.

nickf
So I could put that in my default.ctp in my layouts folder and it would pull from the database right? Sorry if I sound stupid/confused, but I just ported all my kohana stuff to cakePHP and it's a little troublesome to get everything all figured out.
TheMoonMaster
@TheMoonMaster An element is just a reusable HTML/PHP "view snippet". To get data into it you can set the data in the controller and pass it into the element, or you can "pull" the data from inside the element using `requestAction`. This is explained in the article nickf links to.
deceze
Awesome, thanks guys.
TheMoonMaster
A: 

As nickf said, you can use elements. Just create a latest-posts.ctp file in views/elements. There you can create a recyclable element.

Now, on views/layouts/default.ctp

$this->render('latest-posts');

There you go.

metrobalderas
Awesome, thanks.
TheMoonMaster