0
votes

In Yii2 Advanced Application font-awesome .css file add in AppAssets

vendor/font-awesome/css/font-awesome.min.css add in frontend and backend AppAssets

frontend->assets->AppAsset.php

<?php

  namespace frontend\assets;

  use yii\web\AssetBundle;

  /**
  * Main frontend application asset bundle.
  */
  class AppAsset extends AssetBundle
  {
     public $basePath = '@webroot';
     public $baseUrl = '@web';
     public $css = [
         'css/style.css',
     ];
     public $js = [
         'js/jquery.min.js',
     ];
     public $depends = [
         'yii\web\YiiAsset',
         //'yii\bootstrap\BootstrapAsset',
     ];
  }
?>

backend->assets->AppAsset.php

<?php

  namespace backend\assets;

  use yii\web\AssetBundle;

  /**
  * Main backend application asset bundle.
  */
  class AppAsset extends AssetBundle
  {
     public $basePath = '@webroot';
     public $baseUrl = '@web';
     public $css = [
         'css/style.css',
     ];
     public $js = [
         'js/jquery.min.js',
     ];
     public $depends = [
         'yii\web\YiiAsset',
         //'yii\bootstrap\BootstrapAsset',
     ];
  }
?>

Thank's in Advanced.....

3

3 Answers

1
votes

You can create new Asset File and Include it in your Layout

class FontAwesomeAsset extends \yii\web\AssetBundle
{

    public $sourcePath = '@vendor/font-awesome/';
    public $css = [
        'css/font-awesome.min.css',
    ];
    public $depends = [
        'yii\web\YiiAsset',
    ];

}

And then call it in your Layout file (commonly views/layout/main.php)

frontend\assets\FontAwesomeAsset::register($this);
0
votes

Vendor folder is not web accessible. One solution is to symlink the css, js, img from vendor folder into the web folder. Then include that. Or here is the Yii way to do it:

For example :

<?php

namespace app\assets;

use yii\web\AssetBundle;

class BootstrapAsset extends AssetBundle {

//set the source path using @vendor or another alias like @bower here
  public $sourcePath = '@bower/bootstrap/dist';

//include css and js relative to the source path set above
  public $css = [
    'css/bootstrap.css',
  ];
  public $js = [
    'js/bootstrap.min.js',
  ];
}

Or Else try this

public $sourcePath = '@vendor';
public $css = [
    'font-awesome/css/font-awesome.min.css',
0
votes

first of all create new asset file [vendorName]Asset with code:

namespace frontend\assets;

use yii\web\AssetBundle;

class [vendorName]Asset extends AssetBundle
{


    /**
     * @inheritdoc
     */
    public $sourcePath = '@vendor/path/to/you/vendor/folder';


    /**
     * @inheritdoc
     */
    public $js = [
    ];

    public $css = [
       'css/youFile.css',
    ];

    public $depends = [
    ];

}

Next is add this file to main asset $depends:

    public $depends = [
..
        'frontend\assets\[vendorName]Asset',
..
];

And thats all