1
我使用Kohana 3.2框架。我有一个静态字符串的变量。 代码index.php
控制器:获取错误:undefined variable;该怎么办?
class Controller_Index extends Controller_Template {
public function action_index()
{
$articles_ = Model::factory('index')->do_magic();
$view_content = View::factory('index/index')->set('query', $articles_);
$this->response->body(View::factory('template/index')
->set('page_title', 'Sākums')
->set('content', $view_content));
}
} // End Welcome
而对于模板控制器(template.php
)代码:
class Controller_Template extends Kohana_Controller_Template {
public $template = 'template/index';
public function before()
{
parent::before();
$config = Kohana::$config->load('common');
$this->template
->set('site_name', $config->site_name);
}
}
而且我的配置文件(common.php
)
return array (
'site_name' => 'reGative.id.lv',
)
我得到的错误:ErrorException [ Notice ]: Undefined variable: site_name
。 问题在哪里?
不工作。同样的错误。 – reGative
您的视图中是否存在$ site_name变量? – matino
是的,$ site_name变量在index.php视图中退出。 – reGative