【发布时间】:2015-12-04 05:39:34
【问题描述】:
我已经编写了一个单独的动作类,它是从这样的控制器调用的:
1) protected/controllers/SoccerController.php
class SoccerController extends Controller
{
public function actions() {
return array (
'index' => 'application\actions\soccer\IndexAction',
'teamlist' => 'application\actions\soccer\TeamListAction'
);
}
}
2) 受保护/actions/soccer/IndexAction.php
class IndexAction extends CAction
{
public $viewFile = 'teamoverview';
/**
* executes the action.
*/
public function run()
{
$team = new SoccerTeam();
$this->controller->render($this->viewFile, array('team'=>$team));
}
}
当我调用 url http://localhost/test/soccer/index 时出现致命错误 Cannot redeclare class IndexAction in C:\wamp\www\test\protected\actions\soccer\IndexAction.php on line 25
任何机构可以帮助我为什么会发生此错误?
【问题讨论】:
-
你为什么要写一个单独的动作类?
-
我没有将所有动作都放在控制器中,而是尝试分解为不同的类。
-
如果你想创建一个单独的模块,或者如果你认为一个控制器有太多动作,你可以创建多个控制器。
-
是的,但我想知道为什么这个解决方案不起作用:)