Passing data around from view to view unlimited number of times without rebuilding the data array |
[eluser]Unknown[/eluser]
I'm loading views from within views multiple times and to avoid rebuilding the data array i create a self-reference to it. $data=array(); $data['data']=&$data; then set some other values $data[' .. ']= ... then load the view $this->load->view('view1',$data); Inside view1 i have <?php $this->load->view('view2',$data); ?> Inside view2 i have <?php $this->load->view('view3',$data); ?> And in view3 i use some of the variables in $data. My question is: are there any reasons not to use this method? Code example below: Controller Code: function index() View: page/index.php Code: $this->load->view('layout/header.php',$data); View: layout/header.php Code: <head><title> Thank you for your time!
[eluser]InsiteFX[/eluser]
Controller: Code: function index() View: page/index.php Code: $this->load->view('layout/header.php'); View: layout/header.php Code: <head>
[eluser]wr5aw[/eluser]
I just posted a simple registry class on github. You can autoload it and use it as a global variable container. Here's the CodeIgniter wiki page: http://codeigniter.com/wiki/Registry After you load it, you can do this: Code: // store a value
[eluser]InsiteFX[/eluser]
CodeIgniters $this->load->vars also makes them global to all Controllers and Views.
[eluser]wr5aw[/eluser]
$this->load->vars is a one shot solution. I think I wrote the registry because I needed something more flexible. |
Welcome Guest, Not a member yet? Register Sign In |