PHPackages                             magicsoft/yii2-select - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. magicsoft/yii2-select

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

magicsoft/yii2-select
=====================

Magic Select

055PHP

Since Jun 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/aramirezarg/yii2-select)[ Packagist](https://packagist.org/packages/magicsoft/yii2-select)[ RSS](/packages/magicsoft-yii2-select/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Magic select \[Beta\]
=====================

[](#magic-select-beta)

Magic select fully utilizes the functionality of , but extends its functionality to function dynamically without configuration.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist magicsoft/yii2-select "*"

```

or add

```
"magicsoft/yii2-select": "*"

```

to the require section of your `composer.json` file.

\#Usage

You can use directly from a form, the widget will dynamically build the selector with dynamic query.

```
echo $form->field($model, 'attribute_id')->widget(\magicsoft\select\MagicSelect::className(), []);

//With this configuration, the widget assumes that its fields of search and return of data are: 'name' or 'description'
```

But you can configure your own search and data return fields

```
echo $form->field($model, 'attribute_id')->widget(\magicsoft\select\MagicSelect::className(), [
     'searchData' => 'code,name,...',
     'returnData' => 'join:code,description'
])?>
```

**searchData** one or more field, separed by ','.
**returnData** this can take tree options: ***join***: join a few fields or attributes, ***attr*** attributes in model, ***field*** one field in bd.

\####Configure multiples select with parent select

```
//This is a parent select
echo $form->field($model, 'country_id')->widget(\magicsoft\select\MagicSelect::className(), []);

//This is a second select
echo $form->field($model, 'state_id')->widget(\magicsoft\select\MagicSelect::className(), [
     'parent' => 'country'
]);

//This is a tree select
echo $form->field($model, 'province_id')->widget(\magicsoft\select\MagicSelect::className(), [
     'parent' => 'state'
]);

//... More select
```

\####Use magic select in gridView (valid for gridView of Krajee)

```
$gridColumns = [
    ['attribute' => 'id', 'visible' => false],
    'name',
    \magicsoft\select\MagicSelect::getDataForGrid([
        'model' => $searchModel,
        'attribute' => 'country_id'
    ]),
    \magicsoft\select\MagicSelect::getDataForGrid([
        'model' => $searchModel,
        'attribute' => 'state_id',
        'parent' => 'cuntry'
    ]),
    ... more columns
]
```

The second select connects with the first, the third with the second....

Module
------

[](#module)

Setup the module in your Yii configuration file with a name magicsoft as shown below.

```
'modules'=>[
   'magicsoft'=>[
        'class' => \magicsoft\select\Module::className(),
        'encryptOptions' => [
            'secretKey' => '205bdf05272043d',
            'secretIv' => '205bdf0512ea37e',
        ],
        'modelsOptions' => [
            'default' => [
                'icon' => 'fa fa-list',
                'modal' => [true, 'free' => ['index', 'create']]
            ],
            'location' => [
                'icon' => 'fa fa-map-marker',
                'title' => ['singular' => 'Location', 'plural' => 'Locations'],
                'group' => ['parent' => 'location', 'shield' => ''],
                'modal' => [true, 'free' => ['index']]
            ],
        ]
    ]
],
//The encryptOptions, you can use your own values
//The modelsOptions, set the particular values for the views
```

Your controller
---------------

[](#your-controller)

Magic Select automatically manages the editing and insertion forms, so configuration must be used in your controller.

```
use magicsoft\select\controllers\MagicController;

class TestController extends Controller
{
    use MagicController;

    public function actionCreate(){
        return $this->save(new Test());
    }
}
```

In your views (form for create or update data)

```
