Kohana模板$ content变量不显示任何内容 [英] Kohana template $content variable shows nothing
问题描述
我有一个Kohana控制器,可扩展Kohana模板类. Kohana模板类具有
I have a Kohana controller that extends Kohana template class. The Kohana template class has
const CONTENT_KEY = 'content';
在此控制器中,我声明了要使用的模板视图:
In this controller I have declared the template view to be used:
public $template = 'homepage_template';
在此控制器中,我还有一些方法和一些关联的视图.
Also in this controller I have some methods, and some associated views.
具有所有这些,当我在 homepage_template 视图中echo $content
时,什么也没显示(视图中没有内容属于此控制器的动作). (我在动作中具有auto_render true).可能是什么原因造成的?
Having all these, when I echo $content
in the homepage_template view, nothing shows (no content from the views that belong to the actions from this controller). (I have auto_render true in the actions). What can be the cause for that?
推荐答案
这就是我使用模板控制器的方式,希望对您有所帮助:
Thats how I use Template Controller, hope it will help:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Template_Default extends Controller_Template
{
public $template = 'templates/default';
protected $auth;
protected $user;
public function before()
{
parent::before();
Session::instance();
$this->auth = Auth::instance();
if (($this->user = $this->auth->get_user()) === FALSE)
{
$this->user = ORM::factory('user');
}
if($this->auto_render)
{
$this->template->title = '';
$this->template->meta_keywords = '';
$this->template->meta_description = '';
$this->template->meta_copywrite = '';
$this->template->header = '';
$this->template->content = '';
$this->template->footer = '';
$this->template->styles = array();
$this->template->scripts = array();
$this->template->bind_global('user', $this->user);
}
}
public function after()
{
if($this->auto_render)
{
$styles = array('css/default.css' => 'screen', 'css/reset.css' => 'screen');
$scripts = array('js/infieldlabel.js', 'js/menu.js', 'js/jquery.js');
$this->template->styles = array_reverse(array_merge($this->template->styles, $styles));
$this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts));
}
parent::after();
}
} // End Controller_Template_Default
P.S.您不应该对内容使用常量. 从Controller_TEemplate_Default扩展您的控制器,并将其绑定为$ this-> template-> content = View :: factory('view的路径');
P.S. you shouldn't use constant for content. Extend your controller from Controller_TEemplate_Default and bind it like $this->template->content = View::factory('path to the view');
这篇关于Kohana模板$ content变量不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!