Multi-level views with variables [SOLVED] |
[eluser]karlis_i[/eluser]
Hi, I'm new to CodeIgniter and whole MVC thing, and I hope you can help me clarify some things. I'm working on an application, that has one main view (header, footer, menu, etc), some content views (tables with clients, bills, etc), and some sub-views for content (info about specific client, etc). HTML is divided this way so that user can load views with Ajax, but I want to make this work with JavaScript turned off too. I know that it is possible to call a view from another view, but I want also to pass variables for view and sub view from controller. For now it looks like this- Controller Code: function something() Views/Main.php Code: ...some html Views/Clients.php Code: ...some html, using client variables like this: <?=$client->id?> Views/Client_info.php is simple, just html and Code: <?=$client_info->name?> I hope I made it clear. So, the question is- is it ok to do so, and if not, how should I do it? Thanks in advance, k_i
[eluser]summery[/eluser]
Hi, karlis_i, Instead of ponderously passing everything from one view to another, just use the $this->load->vars array, which is available to all views. Controller: Code: function something() Views/Main.php Code: ...some html Views/Clients.php Code: ...some html, using client variables like this: <?=$client->id?> $this->load->vars is pretty awesome for getting rid of the problem of passing data among nested views. You can read more about it in the Loader Class documentation.
[eluser]gino[/eluser]
hi, you realy don't need to reset the data array for each view!! Code: //controller hope this helps
[eluser]karlis_i[/eluser]
Thank you, guys, for help! Once again, RTFM proves to be the right way to do it - http://ellislab.com/forums/viewthread/44916 |
Welcome Guest, Not a member yet? Register Sign In |