Loading views within a view file |
[eluser]jdavidson[/eluser]
[quote author="adamp1" date="1271160570"][quote author="jdavidson" date="1271127323"]Not sure if this is helpful but another possibility is to use a simple include within the view such as: Code: <?php include('system/application/views/header.php'); ?> As long as you pass all variables needed to the original view, there is no need to "load" additional views since as far as codeigniter is concerned you have only loaded a single view.[/quote] I wouldn't use this method in an MVC framework since there is no need with $this->load->view. Another thing is the paths have to be absolute/relative which mean if you did change the folder structure you have to go update all include statements.[/quote] You have a good point with the folder structure argument. That definitely makes it much more beneficial to load all views from the Controller. Thanks for the input.
[eluser]Linderman[/eluser]
Ok , i am confused. Why? Because when i Code: <?php $this->load->view('global/header'); ?> The Page view: Code: <?php $this->load->view('global/header'); ?> The header part (which is included in the page): Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/xhtml1-loose.dtd"> The controller: Code: class Infopage extends Frontend { as u can see i am passing the $data['date'] to the page -> then page includes header -> in the header i am calling $date ... and everything is perfect. Why is that? Or maybe the author have different situation and me didnt understand? :red: If so ... sorry!
[eluser]porquero[/eluser]
I think that this is the best solution: Controller Code: public function action() View Code: php + html Template View Code: php + html
[eluser]Unknown[/eluser]
I think I found the solution Code: <?php $this->load->view('header');?> if you want to pass the variables to the next view, you can use the $_ci_data['_ci_vars']. as below: Code: <?php $this->load->view('header', $_ci_data['_ci_vars']);?> Hope it helps. cya
[eluser]InsiteFX[/eluser]
You dont even need to do that! Code: public function action()
[eluser]dmayo2[/eluser]
InsiteFX and others are correct. This thread came up in google on the subject. I've just tweaked my controller and view(s) to follow this scheme. At first, the benefits, not to mention keeping the level of abstraction that MVC provides, wasn't evident until the code was being written. Sure the views have Code: $this->load->view($header); Code: ...
[eluser]adityamenon[/eluser]
[quote author="dmayo2" date="1335969173"]InsiteFX and others are correct. This thread came up in google on the subject. I've just tweaked my controller and view(s) to follow this scheme. At first, the benefits, not to mention keeping the level of abstraction that MVC provides, wasn't evident until the code was being written. Sure the views have Code: $this->load->view($header); Code: ... Indeed. Taking it a step further, I extended the core controller (http://ellislab.com/codeigniter/user-gui...asses.html) and set this $global_data + did load->vars($global_data) inside the __construct(). Now, this code does not need repeating in all the controllers too, just make sure you extend MY_Controller and not CI_Controller.
[eluser]Lewis Cowles[/eluser]
I use a custom autoloaded model to allow views called from a Template model. Code: <?php Code: $this->Template->setHeader('themes/default/header'); Code: $APPLICATION_PATH.'views/themes/default/' hope this helps someone else! P.S. you could also have data specific to the header and footer passed by adding a variable $data = null and two internal properties of the Template class, headerData & footerData
|
Welcome Guest, Not a member yet? Register Sign In |