获取错误:变量未定义;该怎么做


Getting error: undefined variable; what to do?

我使用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);
  }
}

And my config file (common.php)

return array (
  'site_name' => 'reGative.id.lv',
)

我得到错误:ErrorException [ Notice ]: Undefined variable: site_name。问题在哪里?

尝试:
$this->template ->set('site_name', $config->get('site_name'));

编辑:

再看你一眼,我觉得你让你的生活更艰难了。我已经简化了你的代码:

<>之前类Controller_Index扩展Controller_Template {公共函数action_index(){$articles_ = Model::factory('index')->do_magic();$this->template->page_title = 'Sākums';$this->template->content = View::factory('index/index')->set('query', $articles_);}}//结束索引之前<>之前类Controller_Template扩展Kohana_Controller_Template {Public $template = 'template/index';()前的公共功能{父::在();$ this ->模板->:域名= Kohana:: $ config ->加载(共同)->(":域名");}}