1. Go to this page and download the library: Download thtmorais/yii2-many-2-many 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/ */
thtmorais / yii2-many-2-many example snippets
use thtmorais\many2many\Many2ManyBehavior;
class Model extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
[
'class' => Many2ManyBehavior::class,
'id' => 'id',
'attribute' => 'relations',
'relatedModel' => RelatedModel::class,
'relatedModelId' => 'id',
'relatedModelAttribute' => 'model_id',
'relatedModelValidate' => true
],
];
}
}