Welcome Guest, Not a member yet? Register   Sign In
Global Var inside Constructor to pass to view
#1

[eluser]pyrokinesis[/eluser]
Hi everyone,

Is it possible to automatically declare/set a variable in the controller __construct and automatically pass it to the view when every controller method is called???

E.G. ->

Code:
<?
class Sample_Controller extends Controller {
    
    public $data;

    public function __construct() {
        parent::__construct();

        $this->data = array();
        $data['active_menu'] = 'Menu One';
    }
    
    public function function_one($data) {
        $data['page_title'] = 'Sample Page Title';
        //$data['active_menu'] is passed to the main view
        $this->load->view($this->main_view, $data);
    }

    public function function_two($data) {
        $data['page_title'] = 'Another Page Title';
        //Override the default $data['active_menu'] value
        $data['active_menu'] = 'new value';
        $this->load->view($this->main_view, $data);
    }
}
?>

Thanks


Messages In This Thread
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 02:15 AM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 02:20 AM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 02:28 AM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 03:04 AM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 03:32 AM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 12:10 PM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 01:32 PM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 01:55 PM
Global Var inside Constructor to pass to view - by El Forum - 09-03-2009, 08:22 PM
Global Var inside Constructor to pass to view - by El Forum - 08-17-2011, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB