我的控制器有...
class Controller_Staff extends Controller {
public function before() {
parent::before();
$id = $this->request->param('id');
$action = $this->request->param('action');
}
public function action_get($id) {
var_dump($id);
}
}
我的路线是...
Route::set('a', 'bla/<action>/<id>',
array('id' => '\d+', 'action' => '(get|set)'))
->defaults(array(
'controller' => 'staff',
'action' => 'set'
));
当我输入调用
bla/get/42
的 URL (Controller_Staff->before()
)(在调用 action_get()
之前)时,我可以在 $id
中访问 before()
,但 $action
始终是 NULL
。
有没有更好的方法在
$action
方法中访问当前的before()
?
找到了!
最终变得非常容易。
$action = $this->request->action;