duanbai1974 2018-01-31 18:19
浏览 339
已采纳

在yii2中找不到类'common \ models \ LinkAllBehavior'是什么?

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

  • 写回答

1条回答 默认 最新

  • douli8428 2018-01-31 19:04
    关注
    LinkAllBehavior::className()
    

    above line is causing this, if you are using yii2-linkall

    try adding

    use cornernote\linkall\LinkAllBehavior;
    

    on top of your model code along with other use statements

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 关于加载卡的问题有能知道这个要怎么处理吗?
  • ¥100 rtmpose姿态评估
  • ¥15 java 通过反射找路径下的类,打包后就找不到
  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,
  • ¥15 centos7系统下abinit安装时make出错
  • ¥15 hbuildex运行微信小程序报错
  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy
  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。