CodeIgniter Forums
Question about $this->load->vars($array) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Question about $this->load->vars($array) (/showthread.php?tid=23104)



Question about $this->load->vars($array) - El Forum - 09-30-2009

[eluser]shinokada[/eluser]
I read the user guide about loader class.

I understood most of them except, $this->load->vars($array.

I came to a code like this and I don't really understand what's going on here.

Code:
function index()
    {
        $data['heading'] = 'FreakAuth examples';
        $data['page'] = $this->config->item('FAL_template_dir').'template/examples/examples';
        $this->load->vars($data);
        $this->load->view($this->_container);
    }

Could anyone explain about $this->load->vars($array) for me please?

Thanks in advance.


Question about $this->load->vars($array) - El Forum - 09-30-2009

[eluser]Colin Williams[/eluser]
That method takes the array you pass, extract()s it, making the data available to any and all views you load.

For instance, these two pieces of code have basically the same effect:

Code:
$data = array('colors' => array('green', 'blue', 'red'));
$this->load->view('colors', $data);

Code:
$this->load->vars(array('colors' => array('green', 'blue', 'red')));
$this->load->view('colors');

$this->load->vars() is especially useful when you have variables you want to use in all views (like maybe site name, username, is_logged_in, etc).


Question about $this->load->vars($array) - El Forum - 09-30-2009

[eluser]shinokada[/eluser]
Thanks. Now I understand it.

Regards.


Question about $this->load->vars($array) - El Forum - 10-01-2009

[eluser]Shiro[/eluser]
recently I had update my code from
Code:
$this->load->vars($data);
$this->load->view($this->_container);

to

Code:
$this->load->view($this->_container, $data);

save a line space