A
A
Al3x4kov2017-01-13 20:32:08
Yii
Al3x4kov, 2017-01-13 20:32:08

Has anyone seen a good article or video on creating modules?

Friends, tell me, please.
I understand with yii2. There was a necessity to write the module.
My actions:
1) I made a module through gii.
2) As a result, I have 3 folders (controllers, models, views) and the file itself in the root module.php with init.
3) I now need to add css, js files.
4) Created an assets folder in the module root and 2 css, js folders with files inside.
Now I can't find how to connect them. It seems like you need to create another moduleAsset.php file in the root folder of the module and connect everything in it. But there is a hitch and I don’t understand how to proceed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-01-16
@Al3x4kov

first you need to create a set of resources that will describe what files you need to include and where to get them from. You can place it in the root of the module, and describe it like this:

class MyAsset extends \yii\web\AssetBundle
{
    public $js = [
        'js/file1.js'
    ];

    public $css = [
        'css/file1.css'
    ];

    public function init()
    {
        $this->sourcePath = __DIR__ . DIRECTORY_SEPARATOR . 'assets';
    }
}

after that, in the views where you need to use this set of resources, just connect it like this:
PS I generally recommend that you read the documentation and understand the resource sets, how they are arranged and how they work

D
Dmitry, 2017-01-13
@slo_nik

Good evening.
Start with these two articles.
First
Second

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question