YII2, adding fontawesome

Source: Internet
Author: User
Tags chrome developer chrome developer tools

First, the initialization of the project

Initialize with Composer.

Composer Create-project--prefer-dist yiisoft/yii2-app-basic myapp (or use PHP Composer.phar create-project--prefer-dist Yiisoft/yii2-app-basic MyApp

Second, installation Fontawesome

Still installed through Composer. Search Packagist.org Official Package list, we found the configuration of Fontawesome. will be FortAwesome/Font-Awesome": "*" added to the project's Composer.json configuration file.

"require": {    "PHP":">=5.4.0",    "Hybridauth/hybridauth":"Dev-master",    "Fortawesome/font-awesome":"*",//<-here    "Yiisoft/yii2":"*",    "Yiisoft/yii2-swiftmailer":"*",    "Yiisoft/yii2-bootstrap":"*",    "Yiisoft/yii2-debug":"*",    "yiisoft/yii2-gii":"*"},

then run composer update (or PHP composer.phar update) to pull the Fontawesome package from Github to the project locally.

Iii. creating a Fontawesome Resource bundle (Asset bundle)

In order to use these libraries, we need to /assets create a project directory under theFontAwesomeAsset.php

<?PHPnamespaceApp\assets;use Yii\web\assetbundle;classFontawesomeasset extends assetbundle{//The following resource files are not available in the Web directory and cannot be accessed directly by the browser. So we need//Specifies the SourcePath property. Note @vendor This alias, which represents the Vender directory     Public$sourcePath ='@vendor/fortawesome/font-awesome';  Public$css = [    'Css/font-awesome.css',    ];}

To use a resource bundle:

1. Introduce this resource bundle on a specific page

// These two sentences are written directly in the view on that page. Use app\assets\fontawesomeasset; Fontawesomeasset::register ($this);

2. Introduce it globally or as a dependent reference to another resource. Add it to the asset/appasset.php of the project:

<?PHP/** * @linkhttp://www.yiiframework.com/* @copyright Copyright (c) Yii software LLC * @licensehttp://www.yiiframework.com/license/ */namespaceApp\assets;use Yii\web\assetbundle;/** * @author Qiang Xue <[email protected]> * @since 2.0*/classAppasset extends assetbundle{ Public$basePath ='@webroot';  Public$BASEURL ='@web';  Public$css = [        'Css/site.css',    ];  Public$js = [    ];  Public$depends = [        'Yii\web\yiiasset',        'Yii\bootstrap\bootstrapasset',        'App\assets\fontawesomeasset',    ];}

Refresh the page to see the CSS, JS resources that have been introduced (as shown in Google Chrome developer tools)

YII2, adding fontawesome

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.