Welcome Guest, Not a member yet? Register   Sign In
Assign data variable in the constructor?
#1

[eluser]Taff[/eluser]
Hey.
I'm passing a couple of variables to a view using

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

of which one variable is a title

Code:
$data['title']="This is the title";

which works fine if I assign in the function (index() in this case)

but I would like to set a default title in the constructor (I think it's called the constructor)

Code:
class Task extends Controller {

    function Task()
    {
        parent::Controller();
        $this->load->model('/taskmodel','model');
        $data['title']="cool";
    }
    
    function index(){    
        $data['tasks']=$this->model->get_tasks($this->user_id,0);
                //Doesn't send $data['title'] to the view
        $this->load->view('tasks/default_view',$data);
    }
}

I would have expected it to work...but I expect everything to work until I try it.

Am I doing something wrong, is it not possible, or is there a workaround (I thought maybe $data['title']=$this->config->item("cool")Wink

Thanks for any help,
Taff


Messages In This Thread
Assign data variable in the constructor? - by El Forum - 05-17-2008, 08:08 AM
Assign data variable in the constructor? - by El Forum - 05-17-2008, 08:40 AM
Assign data variable in the constructor? - by El Forum - 05-17-2008, 09:00 AM
Assign data variable in the constructor? - by El Forum - 05-17-2008, 09:04 AM
Assign data variable in the constructor? - by El Forum - 05-17-2008, 10:35 AM
Assign data variable in the constructor? - by El Forum - 05-17-2008, 12:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB