public function init() { parent::init(); $jsFile = '@app/views/' . $this->id . '/ajax.js'; // Publish and register the required JS file Yii::$app->assetManager->publish($jsFile); $this->getView()->registerJsFile(Yii::$app->assetManager->getPublishedUrl($jsFile), ['depends' => [\yii\web\YiiAsset::className()]]); }
/** * @inheritdoc */ protected function publishExtensionResources() { /** @var View $resourceManager */ $resourceManager = $this->getResourceManager(); // Initialization of extension resources $assetsExt = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . 'assets'; $assetsPaths = \Yii::$app->getAssetManager()->publish($assetsExt); // [0] - path, [1] - URL $resourceManager->registerJsFile($assetsPaths[1] . '/resource-smart-load.js', ['depends' => [\yii\web\JqueryAsset::className(), \yii\web\YiiAsset::className()]]); }
public function init() { $this->depends = array_merge([JqueryAsset::className(), YiiAsset::className()], $this->depends); $this->css = array_merge([YII_DEBUG ? 'vendor/materialize/css/materialize.css' : 'vendor/materialize/css/materialize.min.css'], $this->css); $this->js = array_merge([YII_DEBUG ? 'vendor/materialize/js/materialize.js' : 'vendor/materialize/js/materialize.min.js'], $this->js); }
<?php use yii\helpers\Html; use yii\helpers\Url; use yii\widgets; $this->registerAssetBundle(\yii\web\YiiAsset::className(), \yii\web\View::POS_HEAD); $this->registerAssetBundle(\yii\bootstrap\BootstrapAsset::className(), \yii\web\View::POS_HEAD); $this->registerAssetBundle(\app\assets\AppAsset::className(), \yii\web\View::POS_HEAD); $this->beginPage(); ?> <!DOCTYPE html> <html lang="<?php echo Yii::$app->language; ?> "> <head> <meta charset="<?php echo Yii::$app->charset; ?> "/> <link rel="icon" type="image/png" href="/img/fav.png" /> <title><?php echo Html::encode($this->title); ?> </title> <?php $this->head(); ?> <?php echo Html::csrfMetaTags(); ?>