yaf
yaf copied to clipboard
关于相同Action使用
用官方的例子:
class ProductController extends Yaf_Controller_Abstract {
protected $actions = array(
"index" => "actions/Index.php",
);
}
class IndexAction extends Yaf_Action_Abstract {
public function execute ($name, $id) {
assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->getRequest()->getParam("id"));
}
}
由于我的业务比较复杂,我希望通过Action的方式来处理,假如我已经有一个ProductController的IndexAction,那么我将来有一个OrderController的IndexAction,也需要放在actions目录下,可是这样就重复了,修改该文件名又不能自动装载,是不是意味着我的路由需要被改变?
@lancerhe 以下方式测试OK 在OrderController中使用 protected $actions = array( "index" => "actions/Order/Index.php", ); 在ProductController中使用 protected $actions = array( "index" => "actions/Product/Index.php", );
需要注意的是 默认情况下 actions是在application目录下。
当多modules的时候,还是会在application/actions里找, 如果默认可以在和modules/Api/controllers同级目录找就好了,即modules/Api/actions。
目前只能在modules/Api/controllers/Index.php里写了:
public $actions = [
//'index' => 'actions/index.php',
'index' => 'modules/Api/actions/User/Index.php'
];
如果actions里的modules/Api/
可以省掉就好了,不然要写很多,不过目前还不知如何去掉。