S
S
Sergey Beloventsev2017-05-04 14:23:22
Yii
Sergey Beloventsev, 2017-05-04 14:23:22

How to connect js files to extension via Asets?

Actually, I didn’t find it anywhere in the documentation, only based on examples I guess
that we need to create an assets folder in the extension, create a file MyExtensionsAssetsinherited from AssetBundle, but then the question is to work through properties cssand javascriptor through a method init()and how to connect jqueryUi, and how to connect your script, and then another question is how connect assets like this:MyExtensionsAssets::register($this);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2017-05-04
@Sergalas

you need to create an assets folder in the extension create a file MyExtensionsAssets inherit from AssetBundle

Yes
Connect all scripts and styles of the extension through the css and js properties. You should not use init () for these purposes and produce unnecessary code
Put it in the appropriate folder and register it in js
If the extension is inherited from the base class \yii\base\Widget then in the extension through MyExtensionsAssets::register($this->view), if not - then only in the view through MyExtensionsAssets::register($this),
PS next time structure questions are not easy to answer

M
Maxim Timofeev, 2017-05-04
@webinar

You need to connect in view. You will not add all js for the entire module, for example? So here the correct answer depends heavily on what kind of extension you have.

M
mitaichik, 2017-05-04
@mitaichik

Everything is described in the documentation https://github.com/yiisoft/yii2/blob/master/docs/g...
You can also see how it is implemented in Yii itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question