Welcome Guest, Not a member yet? Register   Sign In
Passing Variables from one controller to its extended controller
#4

[eluser]LuckyFella73[/eluser]
Yes you can do that.

Code:
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');

class Backend_Controller extends MY_Controller
{
var $variable_used_by_login_too = 'value from backend_controller';

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

        $this->load->library('session');

        $cms_template = $this->config->item('cms_template');

        $this->data['template'] = $cms_template;
    }

// in case you want to alter the value depending on the controller that extends this one
function set_variable_used_by_login_too($data)
{
  $this->variable_used_by_login_too = $data;
}
}





// Login Controller
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends Backend_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $js_page_addons = '[removed][removed]';

        $page_view = 'login_view';

        $this->data['js_page_addons'] = $js_page_addons;
        $this->data['page_view'] = $page_view;
        $this->load->view('cms/' . $cms_template . '/usermanagement/index_view', $this->data);
    }

public function test()
{
  echo "Actual value of variable/ Property set in backend_controller: ".$this->variable_used_by_login_too;

  $this->set_variable_used_by_login_too('overwritten value from backend_controller');

  echo "Actual value of variable/ Property set in backend_controller: ".$this->variable_used_by_login_too;
}
}


Messages In This Thread
Passing Variables from one controller to its extended controller - by El Forum - 01-08-2013, 09:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB