S
S
Sergey Beloventsev2019-07-24 08:44:39
Yii
Sergey Beloventsev, 2019-07-24 08:44:39

Why aren't scripts written in the assets folder?

created a widget in common/widget connected its asset in this way

public function init()
    {
        ModalAssets::register($this->getView());
    }

here is the asset itself
class ModalAssets extends AssetBundle
{
    public $publishOptions = [
        'forceCopy' => YII_DEBUG,
    ];
    //public $basePath = '@backend/widgets/companyModal';
    public $sourcePath = __DIR__ . '/assets';
    public $baseUrl = '@web';
    public $css = [];

    public $js = [
        '/js/modal.js'
    ];
    public $depends = [
        YiiAsset::class,
        BootstrapAsset::class,
    ];
}

but for some reason the script is not written in the assets folder and the browser shows the connection
Tell me why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-07-24
@slo_nik

Good morning.
Try moving it ModalAssets::register($this->getView());to the method run();
In ModalAssets, in the init() method

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

Widget structure.
assets /* js and css */
view /* view widget */
ModalWidget.php
ModalAssets.php

The first slash is redundant
public $js = [
   '/js/modal.js'
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question