Well, if I get you right, you are looking for something like this:
public function behaviors() { $model = MyModel::find()->someQuery(); $action = Yii::$app->controller->action->id; return [ 'someBehavior' => [ 'class' => 'behavior/namespace/class', 'callback' => function() use ($model, $action) {
Since behaviors() is just a method, you can declare any variables and add any logic you want, the only convention you have to follow is that the return type must be an array.
If you use your behavior, you can use the events() method, where you can bind your behavior methods to specific events. For instance.
class MyBehavior extends Behavior { public function events() { return [ \yii\web\User::EVENT_AFTER_LOGIN => 'myAfterLoginEvent', ]; } public function myAfterLoginEvent($event) {
In this example, myAfterLoginEvent will be executed after the user successfully logs into the application. $event variable will be passed by the framework and depending on the type of event it will contain different data. Read about the event object
UPDATE:
As I now see, my answer was more general regarding events and behavior. And now that you have added the code, I can suggest you to redefine the beforeAction($action) behavior method with the following code:
public function beforeAction($action) { $actionID = $action->id; foreach ($this->rules as &$rule) { $model = &$rule->authManager['model'];
Also look at the AccessControl method of the beforeAction method , it calls the allows method for each rule, passing it the current action as a parameter. Therefore, if you have a class that extends AccessRule, you can either override the method ($ action, $ user, $ request) or matchCustom($action) to set the appropriate model script. Hope this helps.
Another alternative:
override runAction($id, $params = []) controller runAction($id, $params = []) . Here $ id - actionID is exactly what you need. Check the identifier, install the appropriate model script and call parent::runAction($id, $params);