Reading action params in ACF's matchCallback

I have a typical / classical ACF declaration, in my app-basic application, that uses matchCallback:


public function behaviors()

{

	return [

    	'access' => [

        	'class' => AccessControl::className(),

        	'rules' => [

            	[

                	'allow' => true,

                	'roles' => ['@'],

                	'matchCallback' => function ($rule, $action) {

                    	echo 'Yii::$app->controller->actionParams = '.print_r(Yii::$app->controller->actionParams, TRUE);

                    	echo '$action->controller->actionParams = '.print_r($action->controller->actionParams, TRUE);

                    	echo '$action = '.print_r($action, TRUE);

                    	die();

                	}

            	],

        	],

    	]

	];

}

To my surprise, I found this:

How can this be true? Why action parameters are not available when evaluating matchCallback?

And – of course – how to read them, if my access rule requires to check one of action parameters to judge, whether user can access particular action or not?

EDIT: You can, of course, read action parameters using the brutal way of:


echo '$_GET = '.print_r($_GET, TRUE);

But, I don’t like brutal solutions and it really bothers me, why actionParams are empty at this stage?

Tony’s answer in Stack Overflow:

Controller class has method bindActionParams() which is invoked by \yii\base\Action when it begins to run with the given parameters. So at first controller invoke an action method and run it with params and then action bind its params to controller. But AccessControl check is executing much earlier before action is running, that’s why actionParams are empty. Here is an request lifecycle. As you can see before action gets executed controller performs filters, one of which is AccessControl.

If you dont like "brutal" way, consider use of Yii::$app->request->get() which also will test parameter for isset.