2017 © Pedro Peláez
 

yii2-extension yii2-related-behavior

image

dd174/yii2-related-behavior

  • Wednesday, October 19, 2016
  • by DD174
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3,582 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 7 Versions
  • 15 % Grown

The README.md

Yii2 Related behavior for Yii 2

Обновляет (создает/изменяет/удаляет) связи модели, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer require dd174/yii2-related-behavior

Usage

in Model behavior, (*4)

    public function behaviors()
    {
        return array_merge(
            parent::behaviors(),
            [
                ...
                [
                    'class' => RelatedBehavior::class,
                    'relations' => ['relatedName'],
                    // optional:
                    'scenarios' => ['relatedName' => ['create' => 'create', 'update' => 'update']],
                ],

in Controller, (*5)

$model->loadRelation('relatedName', Yii::$app->request->post(), 'keyPost');

Tips

in related Model unique formName, (*6)

private $formName;

/**
 * @param null $unique необходим для получения доступа к файлам ($_FILES) в новой моделе
 */
public function setFormName($unique = null)
{
    $unique = $unique ?: ($this->primaryKey ?: uniqid('new', true));
    $this->formName = parent::formName() . '[' . $unique . ']';
}

/**
 * Составляем свое name, что бы легко использовать на одной странице форму с несколькими экземплярами этой модели
 * @return string
 */
public function formName()
{
    if (!$this->formName) {
        $this->setFormName();
    }

    return $this->formName;
}

Credits

Author: Danil DD, (*7)

Email: dd174work@gmail.com, (*8)

The Versions

19/10 2016

dev-master

9999999-dev

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

19/10 2016

v1.0.3

1.0.3.0

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

19/10 2016

dev-dev

dev-dev

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

14/04 2016

v1.0.2

1.0.2.0

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

25/02 2016

v1.0.1

1.0.1.0

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

24/02 2016

dev-composite-PK

dev-composite-PK

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related

15/02 2016

v1.0.0

1.0.0.0

  Sources   Download

BSD-3-Clause

The Requires

 

by Danil DD

yii2 behavior activerecord related