D
D
Damir Shaniyazov2021-11-06 00:21:06
Yii
Damir Shaniyazov, 2021-11-06 00:21:06

How to create your own Asset class for a separate module?

Hello! I am writing a module and I want to create my own Asset class for it (let it be called RbacAsset).
How can I make css and js (other) files attached to the layout?

<?php

namespace app\modules\rbac\assets;

class RbacAsset extends \yii\web\AssetBundle
{
    public $basePath = '@rbac';
    public $baseUrl  = '@rbac';

    public $css = [
        'css/tailwind.css'
    ];
}


<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
        '@rbac'  => '@app/rbac/web'
    ],
    'modules' => [
        'rbac' => [
            'class' => 'app\modules\rbac\Module',
        ],
    ],

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lykasov, 2021-11-07
@lykasov-aleksandr

In the desired layout / view, connect the assets you need:

use app\modules\rbac\assets\RbacAsset;
RbacAsset::register($this);

Using Asset Bundles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question