While I am testing yii2 multiple select2 tutorial, I faced the error "Class 'common\models\LinkAllBehavior' not found".
Here is my model code,
public $tag_ids;
public static function tableName()
{
return 'post';
}
public function rules()
{
return [
[['title', 'body','tag_ids'], 'required'],
[['body'], 'string'],
[['title'], 'string', 'max' => 255],
];
}
public function attributeLabels()
{return [
'id' => 'ID',
'title' => 'Title',
'body' => 'Body',
];}
public function behaviors()
{
return [
LinkAllBehavior::className(),
];
}
public function afterSave($insert, $changedAttributes)
{
$tags = [];
foreach ($this->tag_ids as $tag_name) {
$tag = Tag::getTagByName($tag_name);
if ($tag) {
$tags[] = $tag;
}
}
$this->linkAll('tags', $tags);
parent::afterSave($insert, $changedAttributes);
}
public function getPostToTags()
{
return $this->hasMany(PostToTag::className(), ['post_id' => 'id']);
}
public function getTags()
{
return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable('post_to_tag', ['post_id' => 'id']);
}
}
So, I would like to know what is LinkAllBehavior and how does it work?
Thanks