diiimonn / yii2-behavior-relation-follow
关于此包最新版本(v1.0.0)没有可用的许可证信息。
v1.0.0
2015-02-23 12:23 UTC
This package is not auto-updated.
Last update: 2024-09-28 16:41:31 UTC
README
关系数据管理的模型行为
安装
使用composer安装
$ php composer.phar require diiimonn/yii2-behavior-relation-follow "dev-master"
或
"diiimonn/yii2-behavior-relation-follow": "dev-master"
将以下内容添加到您的 composer.json
文件的 require
部分。
用法
在 MyModel.php 中
... use diiimonn\behaviors\RelationFollowBehavior; ... public function behaviors() { return [ ... [ 'class' => RelationFollowBehavior::className(), 'relations' => [ 'books', // relation name ] ], ]; } public function getBooks() { return $this->hasMany(BookModel::className(), ['id' => 'book_id'])->via('authorBooks'); } public function getAuthorBooks() { return $this->hasMany(AuthorBooks::className(), ['author_id' => 'id']); } ...
在 my-view/_form.php 中
从关系模型中选择多个。建议使用 yii2-widget-checkbox-multiple