CI 搭建CMS框架

1. 继承类只能从core或者其他系统内置的目录中继承,不支持随便继承。

2. 本例子中是从core目录中继承CI_Controller类,而且名字有特殊要求,需要MY_ 开头,并且后面要有继承的类的名字,比如MY_Controller。

3.在MY_Controoler中,构建父类。代码如下

class MY_Controller extends CI_Controller{

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

             $this->load->model('rbac_model');
             $this->load->helper('url_helper');
        }



        public function topleft()
        {
        
        $data['rbac'] = $this->rbac_model->get_rbac();


        $this->load->view('pf_top');
        $this->load->view('pf_left',$data);
    

        
        } 

        public function right(){
                $this->load->view('pf_right');
    
        }

        public function bottom(){

                $this->load->view('pf_bottom');
        }

        public function index(){

            $this->topleft();
            $this->right();
            $this->bottom();
        }
    }

代码的一部分是用了用了后台显示的。

在具体的子类中,需要重载父类,并且重写right方法,即可实现右侧显示的更换。

 1 Class Pf_first extends MY_Controller {
 2 
 3     
 4         
 5     public function index(){
 6 
 7         parent::index();
 8 
 9     }
10 
11     public function right(){
12         $this->load->view('pf_right');
13     }
14 
15     }

通过重写right,即可实现右侧代码的更换。

原文地址:https://www.cnblogs.com/sdgtxuyong/p/7159335.html