Question about $this->load->vars($array)

#1
[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.

#2
[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).

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

Regards.

#4
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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