【发布时间】:2014-09-06 03:42:39
【问题描述】:
我在控制器的开头有以下代码(我正在使用 Yii):
protected function beforeAction($action = null)
{
switch ($this->action->id)
{
case 'Images':
// Do something
break;
// ...
}
if ($this->action->id == 'index' || $this->action->id == 'videos')
{
// Do something else
}
return true;
}
public function actionIndex()
{
// ...
}
public function actionVideos()
{
// ...
}
public function actionImages()
{
// ...
}
如您所见,if 语句和 switch 语句都使用 $this->action->id,它返回动作名称。
在switch语句中,它只接受“Images”,大写字母的问题,而$this->action->id返回一个小写字符串。
我什至尝试编写另一个 if 语句而不是 switch - 但同样的问题。
另外,尝试检查字符串 $this->action->id 返回 actionImages() 和其他 - 都是小写。
【问题讨论】:
标签: php yii controller action