Welcome Guest, Not a member yet? Register   Sign In
Nesting views
#1

[eluser]NachoLabs[/eluser]
Hi, I just found out about CodeIgnite yesterday, and spent all day looking into it, I think it could really help me in my job.

Today I started implementing it and I hit a hard stop when I noticed there wasn't an easy way to nest views. For example if i want to include a view in another view I can, but I can't pass the $data array to it, since it's been extracted into the first view.

Is there any way to bypass this?
#2

[eluser]jedd[/eluser]
Hello NachoLabs and welcome to the CI forums.

[quote author="NachoLabs" date="1255401446"]
Hi, I just found out about CodeIgnite yesterday ...
[/quote]

And today you can find out about the [url="http://codeigniter.com/wiki/FAQ"]CodeIgniter FAQ in the wiki[/url] that covers this stuff quite nicely.
#3

[eluser]skunkbad[/eluser]
Nesting views is easy. Nesting nested views that are nested would be easy.

//inside controller method
$data['innerview'] = $this->load->view('innerview','',TRUE); //this is the nested view
$this->load->view('mainview',$data); //this is the main view

//inside the main view (views/mainview.php)
echo $innerview;
#4

[eluser]NachoLabs[/eluser]
OK, sorry about asking a FAQ. I looked around the forum a bit and didn't saw anything helpful, but it was a quick overlook. I apologize.

I found the answer I was looking for here: http://ellislab.com/forums/viewthread/44916/
It's exactly what I needed, I didn't want to edit the core or have to import 3rd party libraries. Moreover, I am unhappy with the practice of joining various views using load->view('view','',TRUE), because actually I am unhappy with defining the layout in the controller. The view part should be in the views and the hardcore programming shoud be in the controllers, to keep things tidy.

Anyhow, consider this thread closed. Thanks!
#5

[eluser]skunkbad[/eluser]
I'm certainly not going to argue about a method that Rick Ellis came up with not being good, but I feel that the other way is more clear for me, probably because I came from Kohana, and the way to nest views is similar. I do think it is awesome that CI is so flexible, and has both methods available. Just another example of why CI is the best.
#6

[eluser]Colin Williams[/eluser]
Technically, your code shouldn't be concerned at all with layout. That should be done with CSS. Furthermore, in MVC, the view and controller work together to construct the interface, not necessarily the view independently.




Theme © iAndrew 2016 - Forum software by © MyBB