Wie übergibt Codeigniter Werte von my_controller an andere Controller?
仅有的幸福
仅有的幸福 2017-05-16 16:43:33
0
1
364

My_Controller sagt Folgendes:


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;
    }
}

Dann bin ich im 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();

//***

Das ist derzeit machbar, aber es muss in der Seitenmethode geschrieben werden$data=$this->get_right();这句。
感觉不方便。想在__construct后就能获取到$data
Wie soll es geschrieben werden?

仅有的幸福
仅有的幸福

Antworte allen(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();

//***
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage