I can't 开发者_高级运维seem to set the $template
variable dynamically of a site built on Kohana.
If I extend the Template_Controller class, I can set the template name like this:
public $template = 'template_file_name';
But I can't set it dynamically like:
public $template = $this->setTemplate();
or
switch($var):
default:
public $template = 'filename';
break;
endswitch;
Changing the $template
variable using $this->template
in the constructor breaks the Template_Controller somehow:
Fatal error: Call to a member function render() on a non-object
I need to set the template filename based on a variable set in the constructor, or perhaps pulled from an external library.
Any ideas how to make this possible?
this link may have the answer:
http://stii.co.za/php/overriding-default-template-in-kohana-php/
just run your template constructor as this:
public function __construct()
{
$this->template = 'foobar';
parent::__construct();
}
I do it like this:
public function action_myaction()
{
// template
$this->template = "template/overlay";
parent::before();
// display
$this->template->title = 'My Action';
$this->template->content = View::factory('myaction')
}
More information here: http://www.workinprogress.ca/kohana32/
精彩评论