CodeIgniter Forums
Equavalent of Cake "Elements" - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Equavalent of Cake "Elements" (/showthread.php?tid=10110)

Equavalent of Cake "Elements" - El Forum - 07-18-2008


I'm a recent convert to CI, having abandoned the intricacies of CakePHP for something a bit more transparent.

There are a few features I miss, one being the "Elements" construct.

I'm sure there is an easy way to do the same thing in CI.

Do I just use include directives?



Equavalent of Cake "Elements" - El Forum - 07-19-2008

You can use $this->load->view(); inside another view to load subviews (or "view elements").
They share the same variables as the view that included them (I think).

Equavalent of Cake "Elements" - El Forum - 07-19-2008

You're right m4rw3r, it does share it...

What often do is create an index view file that looks like this


And then you can make your controller look like
//do lots of nifty things
$data['page'] = 'myviewfile';
$this->load->('index', $data);

All variables passed to index, will get passed to footer, header and $page.

Equavalent of Cake "Elements" - El Forum - 07-20-2008

After searching some more, I found this info on the forums with some code to do this: