• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loading a view from a variable

[eluser]Nir Gavish[/eluser]
i need to pre-process a view before it is loaded - that is: get it from file, manipulate it, and then load it as a view. while the $return param allows me to *post* process the view, there appears to be no mechanism in-place to *pre*process it. did anyone else encounter this need? what is the most elegant solution? thanks in advance.

[eluser]Michael Wales[/eluser]
$myview = $this->load->view('myview', $data, TRUE);
// do your processing here

[eluser]Nir Gavish[/eluser]
thanks for a fast reply. however, this is not what i'm looking for. i'll elaborate:

i have a view which is the skin of the website, header, footer, sidebar, with an area for content.

now, normally, i would have a 'load->view' method in the content area, which will load the correct view.

however, what i'm aiming for is that this view will contain only "<div id='content'></div>", and i will process it into "<div id='content'>&lt;?$this->load->view($x)?&gt;</div>"

i cannot do it with $return=true, since the view will already be processed, and thus i cannot load internal views.

is that making any sense?

[eluser]Michael Wales[/eluser]
Ah - this is what I call partial views and I discuss it in this blog article, although that article goes well beyond what you are looking for. Here's a quick rundown:


function index() {
  $data['partial'] = 'users/index';

Your variables within the $data array will be passed on from layout.php to all of it's child views automagically.

[eluser]Nir Gavish[/eluser]
hi, thanks again, i understand the concept of partial views, but this is one step further than your avarage partial view, the chief-view isn't meant to contain any php instructions whatsoever, i wish to inject the php *prior* to the execution of the view. this is done so that the chief-view (or master-page / template / whatever you may call it) contains only simple html, and not one line of php.

[eluser]Nir Gavish[/eluser]
hi again, after some inspection, it appears i will have to extend the CI loader if i want this done, add a method like load_view_from_string() or something along those lines, does anyone have any experience with that?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.