2017 © Pedro Peláez
 

yii2-extension yii2-nested-sortable

an implementation of nestedSortable2.0

image

claudejanz/yii2-nested-sortable

an implementation of nestedSortable2.0

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 78 % Grown

The README.md

Nested Sortable

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

an implementation of nestedSortable2.0, (*2)

Installation

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

Either run, (*4)

php composer.phar require --prefer-dist claudejanz/yii2-nested-sortable "*"

or add, (*5)

"claudejanz/yii2-nested-sortable": "*"

to the require section of your composer.json file., (*6)

Prepare Model

In table migrateion:, (*7)

$this->createTable('page', [
    'id'               => $this->primaryKey(),
    'title'            => $this->string(255)->notNull(),
    'parent_id'        => $this->integer()->null(),
    'weight'           => $this->integer(11)->notNull()->defaultValue(1),
]);

$this->createIndex('idx-page-parent_id', 'page', 'parent_id');
$this->addForeignKey('fk-page-parent_id-page-id', 'page', 'parent_id', 'page', 'id', 'SET NULL', 'CASCADE');

In ActiveRecord: for more details on Customizing Query Classes, (*8)

/**
* @inheridoc
*/
public static function find()
{
    return (new PageQuery(get_called_class()))->orderBy('weight');
}

/**
* @return ActiveQuery
*/
public function getParent()
{
   return $this->hasOne(Page::className(), ['id' => 'parent_id']);
}

/**
* @return ActiveQuery
*/
public function getPages()
{
   return $this->hasMany(Page::className(), ['parent_id' => 'id'])->inverseOf('parent');
}

Usage

Once the extension is installed, simply use it in your code by :, (*9)

In view:, (*10)

use claudejanz\yii2nestedSortable\NestedSortable;
echo NestedSortable::widget([
    'items'         => Page::find()->andWhere(['parent_id'=>null])->all(),
    'url'           => ['pages/save-sortable'],
    'contentAttribute' => 'title';
    'itemsAttribute' => 'pages';
]);

In controller:, (*11)

public function actions()
{
    return [
        'save-sortable' => [
            'class' => 'claudejanz\yii2nestedSortable\NestedSortableAction',
            //'scenario'=>'editable',  //optional
            'modelclass' => Page::className(),
        ],
    ];
}

The Versions

29/11 2017

dev-master

9999999-dev

an implementation of nestedSortable2.0

  Sources   Download

BSD-4-Clause

The Requires

 

extension yii2 nestedsortable2.0

29/11 2017

v1.0.2

1.0.2.0

an implementation of nestedSortable2.0

  Sources   Download

BSD-4-Clause

The Requires

 

extension yii2 nestedsortable2.0

21/09 2016

v1.0.1

1.0.1.0

an implementation of nestedSortable2.0

  Sources   Download

BSD-4-Clause

The Requires

 

extension yii2 nestedsortable2.0

21/09 2016

v1.0.0

1.0.0.0

an implementation of nestedSortable2.0

  Sources   Download

BSD-4-Clause

The Requires

 

extension yii2 nestedsortable2.0