Welcome Guest, Not a member yet? Register   Sign In
Set a default variable in my controller constructor
#1

[eluser]sohei[/eluser]
Hi all,
I have some variables that appears often in my controller.
So I want to define them in my constructor:
Code:
function __construct()
        {
            parent::__construct();
$this->load->model('artist_model');
            $data['works'] = $this->artist_model->getWorks(8);
        }
But when I call them in my view, it doesn't work.. Can anyone tell me why?

Thanks,
sohei
#2

[eluser]cideveloper[/eluser]
Code:
function __construct()
{
    parent::__construct();
    $this->load->model('artist_model');
    $data['works'] = $this->artist_model->getWorks(8);
    $this->load->vars($data);
}

Read Loader Class - $this->load->vars($array)
#3

[eluser]sohei[/eluser]
Thanks cideveloper!
#4

[eluser]Dan Bowling[/eluser]
The strategy that I use, which allows inheritance from my base controllers and models is using $this context.

For instance, I set info like this:
Code:
$this->data['foo'] = 'bar';

And when I call a view, it's like this:
Code:
$this->load->view('my/view', $this->data);




Theme © iAndrew 2016 - Forum software by © MyBB