Yii2-在操作前从路由器捕获参数
是否有一种方法可以在beforeAction中从路由器捕获参数,以便控制器中的所有功能都可以使用它 我有这个路由器:Yii2-在操作前从路由器捕获参数,yii,routing,yii2,Yii,Routing,Yii2,是否有一种方法可以在beforeAction中从路由器捕获参数,以便控制器中的所有功能都可以使用它 我有这个路由器: 'http://<user:\w+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>', 'http://'$域'/'=>'/', 我想在控制器中的所有函数中使用作为ID,并且在不将其注入函数的情况下使其可用?这可
'http://<user:\w+>.' . $domain . '/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'http://'$域'/'=>'/',
我想在控制器中的所有函数中使用作为ID,并且在不将其注入函数的情况下使其可用?这可能吗?原始解决方案可以在
bindActionParams
中截取$params
数组:
class ParamController extends Controller {
public $user;
public function bindActionParams($action, $params)
{
if(isset($params['user'])){
// may be some business based on $this or $action
$this->user = $params['user'];
}
return parent::bindActionParams($action, $params); // TODO: Change the autogenerated stub
}
}
当然,您需要从ParamsController
扩展所有控制器。在您的示例中,用户是参数吗?