jmc*_*tie 2 php templates kohana
我似乎无法$template动态设置在Kohana上构建的站点的变量.
如果我扩展Template_Controller类,我可以像这样设置模板名称:
public $template = 'template_file_name';
Run Code Online (Sandbox Code Playgroud)
但是我无法动态设置它:
public $template = $this->setTemplate();
Run Code Online (Sandbox Code Playgroud)
要么
switch($var):
default:
public $template = 'filename';
break;
endswitch;
Run Code Online (Sandbox Code Playgroud)
在构造函数中$template使用更改变量$this->template会以某种方式中断Template_Controller:
致命错误:在非对象上调用成员函数render()
我需要根据构造函数中设置的变量设置模板文件名,或者从外部库中提取.
任何想法如何使这成为可能?
这个链接可能有答案:
http://stii.co.za/php/overriding-default-template-in-kohana-php/
只需运行您的模板构造函数:
public function __construct()
{
$this->template = 'foobar';
parent::__construct();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我是这样做的:
public function action_myaction()
{
// template
$this->template = "template/overlay";
parent::before();
// display
$this->template->title = 'My Action';
$this->template->content = View::factory('myaction')
}
Run Code Online (Sandbox Code Playgroud)
更多信息请访问:http: //www.workinprogress.ca/kohana32/