Selectize Widget for Yii 2

Hello buddies!

I want to install yii2 extension to modify my blog by adding dropdown list but I get this via terminal …

$ sudo php composer.phar require --prefer-dist yii2mod/yii2-selectize "*"

Could not open input file: composer.phar

Anyone to enlighten me to overcome this please.

Thanks

Which steps did you do?

http://www.yiiframework.com/doc-2.0/guide-start-installation.html#installing-yii

I am not able to send a github link to show it clearly since i’m newbie in here but I used this method below

Selectize Widget for Yii 2

[size="3"][/size]

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yii2mod/yii2-selectize "*"

or add

"yii2mod/yii2-selectize": "*"

to the require section of your composer.json.

Usage

Once the extension is installed, simply add widget to your page as follows:

Tagging input:

echo $form->field($model, "attribute")->widget(Selectize::className(), [

    'pluginOptions' => [


        'persist' => false,


        'createOnBlur' => true,


        'create' => true


    ]

]);

Select input:

echo $form->field($model, "attribute")->widget(Selectize::className(), [

    'items' => [


        'Yes',


        'No'


    ],


    'pluginOptions' => [


        'persist' => false,


        'createOnBlur' => true,


        'create' => true


    ]

]);

Tagging input with remote source and default values(If you want render select input, just setup items property):

Setup view file:

// setup the following to get the existing data from database

$model->attribute = ‘first, last’;

// or if the data is an array you can preselect the tags like this

$model->attribute = implode(’, ', [“first”, “last”]);

echo $form->field($model, "attribute")->widget(Selectize::className(), [

     'url' => '/site/search',


     'pluginOptions' => [


        'valueField' => 'name',


        'labelField' => 'name',


        'searchField' => ['name'],


        'persist' => false,


        'createOnBlur' => true,


        'create' => true


    ]

]);

Your action must return data in the json format, for example:

public function actionSearch($query = null)

{

  Yii::$app->response->format = Response::FORMAT_JSON;


  return [


      ['name' => 'Search Item 1'],


      ['name' => 'Search Item 2'],


  ];

}

Usage widget with plugins:

echo Selectize::widget([

    'name' => 'tag-selectize',


    'options' => [


         'data-data' => $values ? Json::encode($values) : null // Set default values


    ],


    'pluginOptions' => [


         // define list of plugins 


        'plugins' => ['drag_drop', 'remove_button'],


        'persist' => false,


        'createOnBlur' => true,


        'create' => true


    ]

]);

"The preferred way to install this extension is through composer."

So did you install composer itself?

See the page I linked to.

I installed yii2 framework itself via composer or do i have to do another composer installation apart from that?

No, but perhaps you renamed "composer.phar" to "composer"?

Yes, I tried to rename it when i failed by using composer.phar but i get the same result of … Could not open input file: composer

Then I don’t know. It says “could not open” not something like “not found” so perhaps reinstall?

Using Sudo should remain in the same dir but what about search path? Try a qualified absolute path.

BTW I used su, then just started with "composer" from the prompt (global installation, renamed to composer). Never saw this kind of problem.