CodeIgniter Forums

Full Version: Best Practice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]stewartf[/eluser]
Would it be considered taboo, to load a view from within a view?

El Forum

[eluser]moodh[/eluser]
Not really, go ahead.

El Forum

[eluser]CappY[/eluser]
Im using that way. I think it's most clear way.

El Forum

[eluser]stewartf[/eluser]
Glad it isn't just me.

Thanks.

El Forum

[eluser]TWP Marketing[/eluser]
In your controller(s), export sub_views as html and store each in a var:
Code:
...
$view_1 = $this->load-view('view_1',$view_data,TRUE); // sub_view 1
$view_2 = $this->load-view('view_1',$view_data,TRUE); // sub_view 2
$this->load_view('main_view',$view_data);  // send your main view to the browser
...

In the main view (main_view.php), use these stored vars to place your sub-view code.
Code:
...
echo $view_1;
echo $view_2;
...

I use this to create dynamic menus which change according to user input and login status