如何在视图文件夹中加载不在视图文件夹中的视图

时间:2011-03-31 11:34:01

标签: codeigniter

我想为我的应用程序制作不同的主题。我将所有主题文件夹保存在http :: //example.com/thems /中,我希望从这些主题文件夹中加载视图以制作自定义模板。

4 个答案:

答案 0 :(得分:2)

只需扩展CI_Loader核心类。 在application / core / MY_Loader.php上创建新文件并扩展__construct方法

class My_Loader extends CI_Loader
{
   function __construct()
   {
      //Change this property to match your new path
      $this->_ci_view_path = APPPATH.'views/';
      $this->_ci_ob_level  = ob_get_level();
      $this->_ci_library_paths = array(APPPATH, BASEPATH);
      $this->_ci_helper_paths = array(APPPATH, BASEPATH);
      $this->_ci_model_paths = array(APPPATH);
      log_message('debug', "Loader Class Initialized");
   }
}

我很感兴趣,如果这个小黑客会起作用:)

答案 1 :(得分:1)

将当前主题放在会话变量$ theme;

然后在加载视图时,在路径中包含会话变量

$this->load->view('themes/'.$theme.'/<page>');

答案 2 :(得分:0)

Phil Sturgeon和其他几个人已经编写了模板库,它们或多或少地支持主题。这允许您保持MVC结构并且相当灵活。

更多the docs

答案 3 :(得分:0)

我基于现有的库制作了一个非常简单的主题切换器。虽然文件仍在views文件夹中,但在views文件夹中是主题子文件夹。

http://keithics.com/blog/php-programming/a-very-simple-theme-switcher-for-codeigniter

相关问题