Kohana错误...尝试分配非对象的属性

时间:2009-11-15 05:46:51

标签: php kohana

所以我试图通过Kohana的第3版指南并继续在hello world创建视图部分时出错。

ErrorException [ Warning ]: Attempt to assign property of non-object
Line 8: $this->template->message = 'hello world';

我将site.php放在application / views文件夹中......这是错误的地方......?

代码......

public $template = 'site';

public function action_index()
{
        $this->template->message = 'hello world';
}

如果有人能说清楚我做错了什么,我会非常感激...谢谢

2 个答案:

答案 0 :(得分:4)

哎呀忘了扩展右边的控制器。

要是

class Controller_Welcome extends Controller {

需要

class Controller_Welcome extends Controller_Template {

答案 1 :(得分:2)

您可能会发现需要添加

public function before()
{
   parent::before();

}
在你的Controller_Welcome

中,它将预先加载&引用扩展控制器