出现错误:未定义的变量;该怎么办?
我使用 Kohana 3.2 框架。我有一个带有静态字符串的变量。 index.php
控制器的代码:
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 [通知]:未定义变量:site_name
。 问题出在哪里?
I use the Kohana 3.2 framework. I have one variable with a static string.
Code for index.php
controller:
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
And code for Template controller (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);
}
}
And my config file (common.php
)
return array (
'site_name' => 'reGative.id.lv',
)
I get the error: ErrorException [ Notice ]: Undefined variable: site_name
.
Where is the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
$this->模板
->set('site_name', $config->get('site_name'));
编辑:
再看一遍后,我认为你让你的生活变得更加困难。我稍微简化了你的代码:
Try:
$this->template
->set('site_name', $config->get('site_name'));
Edit:
After a second look I think you made your life harder. I have simplified your code a little: