问题
I used them before several months. Then I switched to Fuel. Then I switched back to Kohana.
Problem? I have forgot how to correctly use templates (with that I mean Controller_Template
). There was tutorials on Kohana's docs, but now links seem to be broken.
Please remind me how to use them!
回答1:
If you really want to use them, you have to extend Kohana_Template
. Then you would set a public field '$template' to your view name, and then just do $this->template->foo = "foo" to set variables on the template
public class Controller_MyController extends Controller_Template
{
public $template = "my_view";
public function action_foo()
{
$this->template->foo = "foo"
}
}
But the core developers discourage people to use it. You could better use some kind of template engine like Kostache to make up your templates.
回答2:
$template = 'mytemplate';
function action_index() {
$template->content = new View("content");
$template->content->title = "page title"; // depends on the fields in your view
}
this will require that the mytemplate.php and content.php view files exist
来源:https://stackoverflow.com/questions/6245373/templates-in-kohana-3-1