I
I
iceman21122014-10-21 12:35:14
Yii
iceman2112, 2014-10-21 12:35:14

How to install jquery plugin in yii2?

There is a plugin for example selectBox or select2 in the composer packages, how can I install it in my yii application?
As I understand it, the first step is to enter it in composer.json
And then it will be installed in the vendor, how to connect it to the page?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vit, 2014-10-21
@fornit1917

Write the AssetBundle class, in which you specify all the plugin resources, and then simply call the register function in the places you need.
Everything is well written in the documentation about assets: https://github.com/yiisoft/yii2/blob/master/docs/g...

P
phpnt, 2015-03-06
@phpnt

Adding CSS, JS, jQuery and more to Yii...

S
sokollondon, 2019-04-19
@sokollondon

1) Download the bower package. The name (/font-awesome) can be found here https://bower.io/search/
2) Create a file in the \assets folder

namespace app\assets;

use yii\web\AssetBundle;

class FontAwesomeAsset extends AssetBundle
{
    public $sourcePath = '@bower/font-awesome';
    public $css = [
        'css/all.min.css',
    ];
}

3) We connect to the project
class AppAsset extends AssetBundle
{
    ...
    public $depends = [
        'app\assets\FontAwesomeAsset',
        ...
    ];
}

Everything!
If js is required to be connected at the top of the page, then add to the FontAwesomeAsset class:
public $jsOptions = [
    'position' => \yii\web\View::POS_HEAD,
];

Read more here https://www.yiiframework.com/doc/guide/2.0/en/stru...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question