M
M
My joy2018-04-19 17:54:08
Yii
My joy, 2018-04-19 17:54:08

How to use widgets outside of php?

Hi friends!
There is a widget in Yii for example Select2:

<?php echo Select2::widget([
    'name' => 'hiddenselect',
    'data' => $data,
    'options' => ['placeholder' => 'Выберите...'],
    'pluginOptions' => [
      'allowClear' => true
    ],
  ]); 
?>

Question: how else can I connect this widget so that I can use Select2 when I need it, dynamically through separate js files? And now, in order for the asset with select2 to connect to the page, I have to create a widget with the cat above in the hidden block, and only after that use .select2(), otherwise "Call to undefined function select2()" in the console.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2018-04-19
@t-alexashka

Connect the asset yourself.
UPD.
My joy , in order to begin to understand, you need to read the code of the framework, and the packages that you use. For example, in the case of Select2, the asset you need is connected in the registerAssetBundle
method . As soon as you go through the chain of calls, you will understand that all this is launched from the run () method, which is launched by the framework.
To solve your problem, inside the registerAssetBundle method, find which class is being connected and register it yourself in your view file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question