【发布时间】:2012-03-15 11:10:05
【问题描述】:
我正在使用 HMVC 和 Template 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