我正在构建一个KO3网站,我正在创建一个新的Controller_Template,如下所示:
<?php
defined('SYSPATH') or die('No direct script access.');
class Controller_Menu extends Controller_Template {
public $template = "menu/menu";
public function __construct() {
$this->User = \Base\User::getLoggedInUser();
}
public function action_show() {
// Do totally nothing
}
}
这里没有火箭科学。在我的APPPATH。“/ views / menu”目录中,我有一个“menu.php”文件,如下所示:
<?php
echo "foobar";
令人印象深刻吧? ;)
当我尝试加载http://localhost/menu/show
时,出现以下错误:
ErrorException [ Strict ]: Creating default object from empty value
SYSPATH/classes/kohana/controller/template.php [ 44 ]
39 */
40 public function after()
41 {
42 if ($this->auto_render === TRUE)
43 {
44 $this->request->response = $this->template;
45 }
46
47 return parent::after();
48 }
49
SYSPATH/classes/kohana/controller/template.php [ 44 ] » Kohana_Core::error_handler(arguments)
{PHP internal call} » Kohana_Controller_Template->after()
SYSPATH/classes/kohana/request.php [ 1115 ] » ReflectionMethod->invoke(arguments)
APPPATH/bootstrap.php [ 129 ] » Kohana_Request->execute()
DOCROOT/index.php [ 103 ] » require(arguments)
我在其他控制器中实现了类似的功能,它们都完美地工作。所以有人能告诉我这里有什么问题吗?
修改 我在after方法中转储了请求对象,但未设置它,即它的值为null。
答案 0 :(得分:0)
我找到了解决方案。我不得不在我的覆盖构造函数中调用父构造函数。将代码更改为:
class Controller_Menu extends Controller_Template {
public $template = "menu/menu";
public function before() {
$this->User = \Base\User::getLoggedInUser();
}
public function action_show() {
// Do totally nothing
}
}
解决了我的问题。
修改强>
将代码更改为评论中的建议。