在codigniter中创建布局模板时出错

时间:2017-05-08 06:19:58

标签: php layout codeigniter-3

我的项目中有两个布局模板,并且总是加载第一个模板。如何加载第二个模板。

在主用户控制器中如何区分它们。他们是,

Learncontroller.php

class Learncontroller extends Usercontroller{

    public function __construct(){
        parent::__construct();
        $this->load->model("Usermodel","",true);    
    }

    public function index(){
        $id=$this->session->userdata('cp_userid');
        $menuActive= "learning";
        $data['menuActive'] = $menuActive;
        $userdetails=$this->Usermodel->getuserdetails($id);
        $data['userdetails']=$userdetails;
        $result=$this->Usermodel->currentlearningcourses($id);
        $data['details']=$result;
        $data['content']=$this->load->view("user/currentlearningcourses",$data,true);

        $data['title']='My Courses';
        //$this->load->view("user/layout",$data);

        $headerContent = $this->load->view("user/layout",$data,true);
        $this->render($headerContent);
    }
}

Unitcontroller.php

class Unitcontroller extends Usercontroller{
    public function __construct(){
        parent::__construct();
        $this->load->model("Usermodel","",true);
    }

    public function courselearn($id){
        $r=$this->Usermodel->getsectiontopic($id);
        $data['topicId']=$id;
        $data['topicQ']=$r;
        $data['video']=$this->input->post("id");
        $data['id']=$id;
        $data['content']=$this->load->view("user/unit_content",$data, true);

        $courselearnheaderContent = $this->load->view("user/courselearn_layout",$data,true);
        $this->render($courselearnheaderContent);
    }
}

Learncontroller和Unitcontroller具有单独的布局,但始终加载protected $layout = 'user/layout';。当控件来自Unitcontroller时,如何加载此'user/courselearn_layout';

Usercontroller.php

protected $layout = 'user/layout';
protected $courselearn_layout = 'user/courselearn_layout';

protected function render($headerContent) {
    $view_data = array( 'headerContent' => $headerContent);
    $this->load->view($this->layout);
}

始终加载第一页。如何加载第二页也请帮帮我。

0 个答案:

没有答案