且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在codeIgniter中定义一个全局变量(值)

更新时间:2023-11-14 08:33:40

创建一个核心控制器,因为您的过程需要逻辑运算,那么您需要一个方法。

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

您的控制器必须扩展MY_Controller

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