Templates In Kohana 3.1

孤者浪人 提交于 2019-12-23 20:15:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!