Gentlemen,
I’m trying to implement a generic AssetBundle in order to register my assets dynamically(custom .js and .css that only one view uses). After overriding the constructor, and making the call in the view, I get the following error:
Invalid Configuration – yii\base\InvalidConfigException
Missing required parameter "js" when instantiating "app\assets\GenericAsset".
• 1. in C:\wamp\www\tiger\vendor\yiisoft\yii2\di\Container.php
Any help is greatly appreciated.
My class: GenericAsset.php
namespace app\assets;
use yii\web\AssetBundle;
class GenericAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [];
public $jsOptions = ['position' => \yii\web\View::POS_HEAD];
public $js;
public $depends = [ ];
public function __construct($js, $config = []){
$this->js = $js;
parent::__construct($config);
}
}
View:projects.php
<?php
use app\assets\JqgridAsset;
use app\assets\GenericAsset;
use yii\web\View;
use app\assets\app\assets;
JqgridAsset::register($this);
$asset = new GenericAsset([‘js_views/project/projects.js’]);
$asset::register($this);
// Invoke function that was published in the asset
$this->registerJs(“render_projects();”, View::POS_LOAD, ‘my-options’);
?>