开发者

Templates In Kohana 3.1

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!


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.


$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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜