2017 © Pedro Peláez
 

yii2-extension yii2-related

Yii2 Extenstion

image

porcelanosa/yii2-related

Yii2 Extenstion

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii2-related

Yii2 extenstions - relate the similar entities Latest Stable Version Total Downloads, (*1)

Install

composer require porcelanosa/yii2-related

Run migration, (*2)

$ php yii migrate/up --migrationPath=@vendor/porcelanosa/yii2-related/migrations

Set Behavior

For model set Behavior, (*3)

model_id_field_name - field name of primary key model_name_field_name - field name of Name model - for example, 'name' or 'title' post_name - POST attribute for send data, (*4)

public function behaviors()
{
    return [
        'relatedBehavior' => [
            'class' => RelatedBehavior::className(),
            'model_name' => $this::className(),
            'model_id_field_name' => 'id', 
            'model_name_field_name' => 'name',
            'post_name' => 'related_objects',
            'whereCondition' => 'deleted!=1' // Conditions for list of related entities
        ],
    ......
    ]
}    

Use widget

In admin view:, (*5)

echo \porcelanosa\yii2related\RelatedWidget::widget(
    [
        'model'        => $model,
        'model_name'   => $model::className(),
        'behaviorName' => 'relatedBehavior',
        'title'        => 'Похожие модели',
        'placeholder'  => 'Выберите похожие модели ...',
    ]
);

Usage

Get related models, (*6)

<?
use yii\helpers\Html;
$brand = Brands::findOne(1);
foreach($brand->related as $rel) { 
    echo Html::a($rel->name, $rel->slug); 
    echo '<br>';
}
?>

The Versions

04/12 2017

dev-master

9999999-dev https://github.com/porcelanosa/yii2-related

Yii2 Extenstion

  Sources   Download

MIT

The Requires

 

by Alex Porcelanosa

yii2 yii yii 2