PHP code example of diiimonn / yii2-behavior-relation-follow
1. Go to this page and download the library: Download diiimonn/yii2-behavior-relation-follow library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
diiimonn / yii2-behavior-relation-follow example snippets
...
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']);
}
...
$ php composer.phar