Answer the question
In order to leave comments, you need to log in
Why name behaviors in Yii2?
Hello!
Why are behaviors named? Example from yii\filters\AccessControl documentation:
public function behaviors()
{
return [
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => ['create', 'update'],
'rules' => [
// deny all POST requests
[
'allow' => false,
'verbs' => ['POST']
],
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
Answer the question
In order to leave comments, you need to log in
the use of named behaviors allows you to:
1. Detach the behavior from the component, if necessary, using the detachBehavior function
2. Work with the behavior in descendant classes (for example, change the behavior configuration, etc.)
3. Get the behavior object itself and, if necessary, with it work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question