R
R
Roman2014-10-30 09:57:54
Yii
Roman, 2014-10-30 09:57:54

How to connect the necessary js and css files in Yii2 modules in light?

Good afternoon!
Such a problem: there is a module in which I really want to use my layots with styles and js. How to work with them correctly? How to connect correctly?
Thanks in advance for your replies and help!
UPDATE 10/30/2014 17:50
If suddenly someone is just as stupid as I am :)
The problem lay in the fact that it was necessary to arrange the following functions according to the layout:
$this->beginPage()
$this->beginBody()
$this-> endBody()
$this->endPage(
) the template has acquired this form codepaste.ru/18221
Now everything works, but there is a problem with access, since it (CSS) is loaded from the modules folder, reading from there is prohibited, i.e. a 404 error is issued on the request, how to be here? As I understand it, in Yii, for such purposes, it is used to copy all the asset of the module to the main asset folder, which by default is lying around at the root, but how to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gsd, 2015-09-18
@gsd

layet is a complicated thing

S
Sergey, 2014-10-30
@TsarS

In your module do http://www.yiiframework.com/doc-2.0/guide-structur... and in the view of your module include

use app\yourmodule\AppAsset;
AppAsset::register($this);

M
mosvov, 2016-03-02
@mosvov

In the module

public function init()
    {
        parent::init();
        $this->layout = "/column2";

        //register assets
        \Yii::$app->view->on(View::EVENT_BEFORE_RENDER, function ($event) {
            WebAsset::register($event->sender);
        });
        // custom initialization code goes here
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question