kohana从哪个控制器查看?

时间:2012-06-29 12:45:11

标签: view controller kohana verification

我有一个可以从一个控制器的3个动作中的任何一个调用的视图。 但是,该视图应该略有不同,具体取决于引起它的行为(它应该显示3个图标,或者根据所调用的动作显示2个或1个)。我可以在视图中查看导致它的操作,以便我可以使用if语句来检查是否显示每个图标吗?

谢谢。

1 个答案:

答案 0 :(得分:3)

当然,您可以将action值直接传递给视图:

$this->template->action = Request::current()->action();

但View不应该知道Request属性,它是一个控制器逻辑。我建议你从你的行动中传递特殊标志:

public function action_show1()
{
    // show only one icon
    $this->template->icons = array('first');
}

public function action_show2()
{
    // show another two icons
    $this->template->icons = array('second', 'third');
}

public function action_showall()
{
    // show all icons
    $this->template->icons = array('first', 'second', 'third');
}

或为每个图标设置特殊标志(变量)。