【问题标题】:HMVC and Template library (by Phil Sturgeon) in CodeigniterCodeigniter 中的 HMVC 和模板库(Phil Sturgeon 编写)
【发布时间】:2012-03-15 11:10:05
【问题描述】:

我正在使用 HMVCTemplate library(作者 Phil Sturgeon)。当我在代码中使用Modules::run 时会出现问题:

$this->template->title("Some title")->set_partial('header', 'showmessage')->build('showanothermessage', $data);

在 showmessage.php 部分视图中:

echo Modules::run("goodbye");

错误页面出现:

遇到 PHP 错误

严重性:通知

消息:未定义的属性:GoodBye::$agent

文件名:libraries/template.php

行号:122

致命错误:调用成员函数 is_mobile() on 一个非对象 D:\Binh\wamp\www\codeigniter\application\libraries\template.php 上 第 122 行

如何解决这个问题。提前致谢。

更新 我的goodbye 控制器:

class GoodBye extends MY_Controller{
        function __construct(){
            parent::__construct();
        }
        function Index(){ echo "Goodbye"; }
}

我的MY_Controller

class MY_Controller extends CI_Controller{
    function __construct(){
        parent::__construct();
        // default layout
        $this->template->set_layout("home_layout");
    }
}

我的autoload 文件:

$autoload['packages'] = array();
$autoload['libraries'] = array('database','session','template');
$autoload['helper'] = array();
$autoload['config'] = array();
$autoload['language'] = array();
$autoload['model'] = array();

【问题讨论】:

  • 我们可以看看goodbye 控制器吗,您正在扩展的任何基本控制器,以及您的autoload.php?这表明用户代理库没有加载到 goodbye 控制器中,因为 modules::run() 独立于当前控制器运行。
  • 我已经从 GoodBye 控制器中删除了 parent::__construct(); 并且它可以工作。你能解释一下为什么吗?
  • 老实说,我不知道。 application\libraries\template.php line 122 说什么?
  • 上面说:$this->_is_mobile = $this->_ci->agent->is_mobile();
  • 它唯一的意思是Template::_ci 不是一个对象,但我只能猜测会如何发生。您使用的是什么版本的模板库?

标签: templates codeigniter hmvc


【解决方案1】:

我已将我的 MY_Controller 更改为:

class MY_Controller extends MX_Controller{
    function __construct(){
        parent::__construct();
        // default layout
        $this->template->set_layout("home_layout");
    }
}

成功了!

【讨论】:

  • 哦,我完全错过了!是的,您必须扩展MX_Controller 才能使用wiredesignz 的HMVC 并利用扩展的Loader 类、Lang 等。这实际上正好在documentation: "中使用HMVC 功能,例如Modules::run (),控制器必须扩展 MX_Controller 类。”
猜你喜欢
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 2011-08-27
  • 1970-01-01
相关资源
最近更新 更多