How does codeigniter pass values ​​from my_controller to other controllers?
仅有的幸福
仅有的幸福 2017-05-16 16:43:33
0
1
365

My_Controller says this:


class BaseController extends My_Controller {
    // public $data;
    public function __construct() {
        parent::__construct();
        // $this->get_right();
    }
    public function get_right(){
        $data['rightinfos'] = $this->Com_model->get_top20info();
        $data['right0'] = $this->Com_model->get_site_new();
        $data['right1'] = $this->Com_model->get_site_hot();
        $data['right2'] = $this->Com_model->get_site_hot2();
        return $data;
    }
}

Then I am in the site controller:

class Site extends BaseController {
    public function __construct() {
        parent::__construct(); 
        $this->load->model('Site_model'); 
    }

    
    public function page() {
  
        $data=$this->get_right();
        print_r($data);
        die();

//***

This is currently feasible, but the sentence $data=$this->get_right(); must be written in the page method.
Feels inconvenient. If I want to get $data
after __construct, how should I write it?

仅有的幸福
仅有的幸福

reply all(1)
为情所困
class BaseController extends My_Controller {

    public $data;
    
    public function __construct() {
        parent::__construct();
        $this->data = $this->get_right();
    }
    public function get_right(){
        $data['rightinfos'] = $this->Com_model->get_top20info();
        $data['right0'] = $this->Com_model->get_site_new();
        $data['right1'] = $this->Com_model->get_site_hot();
        $data['right2'] = $this->Com_model->get_site_hot2();
        return $data;
    }
}
class Site extends BaseController {
    public function __construct() {
        parent::__construct(); 
        $this->load->model('Site_model'); 
    }

    
    public function page() {
        print_r($this->data);
        die();

//***
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template