• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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