matthew-p/yii2-models-select Select models widget.

Select models widget for Yii2

  1. Installation
  2. Usage

Find and select models in select2 input.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist matthew-p/yii2-models-select "*"

or add

"matthew-p/yii2-models-select": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by:

$form->field($model, 'attribute')->widget(MPModelSelect::class, [
    'searchModel'     => YouActiveRecordModel::class,
    'valueField'      => 'id',
    'titleField'      => 'title',
    'searchFields'    => [
        // convert to orWhere 'id' => query-string and etc.
        'id', 'title', 
        // add related input (will be added to data request and conver to ->andWhere 'category_id' => request value)
        'category_id' => new JsExpression('$("#category-id").val()'),
        // more examples see MPModelSelect::searchFields
    ],
    'dropdownOptions' => [
        'options'       => [
            'placeholder' => Yii::t('app', 'Select models ...'),
            'multiple'    => true,
        ],
        'pluginOptions' => [
            'minimumInputLength' => 1,
        ],
    ],
])

Add action in controller: `php class SampleController extends Controller { ...

public function actions(): array
{
    return array_merge(parent::actions(), [
        'model-search' => [
            'class' => MPModelSelectAction::class,
        ],
    ]);
}

... } `

Define encryption key in params.php: ` 'MPModelSelect' => [

'encryptionKey' => 'RandomKey',

], `

That's all. Check it.

0 0
1 follower
324 downloads
Yii Version: 2.0
License: BSD-3-Clause
Category: Others
Developed by: Matthew P
Created on: Nov 12, 2018
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions