PHP code example of fedornabilkin / yii2-binds

1. Go to this page and download the library: Download fedornabilkin/yii2-binds 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/ */

    

fedornabilkin / yii2-binds example snippets


use fedornabilkin\binds\behaviors\BindBehavior;
use fedornabilkin\binds\behaviors\SeoBehavior;
use fedornabilkin\binds\models\base\BindModel;

class Post extends BindModel
{

    public function behaviors()
    {
        return array_merge_recursive(parent::behaviors(), [
            'SeoBehavior' => [
                'class' => SeoBehavior::class,
            ],
            'BindsBehavior' => [
                'class' => BindBehavior::class,
                'tree' => [
                    // никнэймы корневых узлов дерева каталога
                    'nicknames' => [
                        'visible' => [
                            'multiple' => false, // единичный или множественный выбор
                        ],
                        'categories' => [
                            'multiple' => false,
                        ],
                        'tags' => [
                            'multiple' => true,
                            'asDropdown' => false, // развернутое состояние
                        ],
                    ],
                ],
            ],
        ]);
    }

    /**
     * tableName()
     * rules()
     * attributeLabels()
     * ...
     */
     

    /**
     * модели hasOne, указать для удаления дочерней модели
     * если она связана с родительской один-к-одному
     * 
     * Один комментарий может быть привязан только к одной модели Post
     */
    public function getChildModels()
    {
        return array_merge(parent::getChildModels(), [
            Comment::tableName() => Comment::class,
        ]);
    }
    
    /**
     * @return ActiveQuery
     */
    public function getComments()
    {
        return $this->hasOne(Comment::class, ['uid_content' => 'uid']);
    }
}


use fedornabilkin\binds\models\Catalog;
use fedornabilkin\binds\models\Uid;
use yii\helpers\Html;
use kartik\tree\TreeViewInput;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model frontend\models\Post */


'components' => [
    ...
    
    'view' => [
        'as seo' => [
            'class' => \fedornabilkin\binds\behaviors\SeoBehavior::class,
        ],
    ],
],

'modules' => [

    ...

    'binds' => [
        'class' => 'fedornabilkin\binds\Module',
    ],
    'treemanager' => [
        'class' => 'kartik\tree\Module',
        'dataStructure' => [
            'keyAttribute' => 'id',
        ],
    ],
],

php composer.phar 
 php yii migrate --migrationPath=@fedornabilkin/binds/migrations
html
<div class="post-update">

     $form = ActiveForm::begin();