How to define a global variable(value) in codeIgniter

前端 未结 4 955
悲&欢浪女
悲&欢浪女 2021-01-22 02:58

I simply do not mean how to define a global variable/constant in CodeIgniter. Let me explain: I have made a theme engine which is select-able from the current logged in user\'s

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-22 03:38

    Create A core controller, since your process requires logical operations then you need a method for that.

    application/core/MY_Controller.php

    class MY_Controller Extends CI_Controller
    {
    
       protected $default_theme = 'theme';
    
       public function __construct()
       {
          parent::__construct();
       }
    
       public function get_theme()
       {
             //your code for selecting the current theme selected from
             //the database
             $theme_from_db = '';
    
             return $theme_from_db == NULL ? $this->default_theme : $theme_from_db;
       }
    }
    

    Your Controller must extend MY_Controller

    application/controller/view.php

    class view extends MY_Controller
    {
       public function index()
       {
         $this->load->view($this->get_theme().'result', $data);
       }
    }
    

提交回复
热议问题