在动作级别渲染不同的Kohana模板

时间:2011-11-07 21:32:23

标签: php kohana

我有一个名为'account'的模板的帐户控制器。我只想弄清楚如何为我的登录/忘记密码操作指定不同的模板。

1 个答案:

答案 0 :(得分:5)

我假设您的控制器已延长Controller_Template?在控制器before方法中,您可以检查操作的名称并根据该更改模板:

<?php

class Controller_Account extends Controller_Template {

    // This is the default template used for all actions
    public $template = 'account';

    public function before()
    {
        // You can add actions to this array that will then use a different template
        if (in_array($this->request->action(), array('login', 'forgot_password')))
        {
            $this->template = 'diff_template';
        }

        parent::before();
    }