在Yii2高级应用程序中,字体非常棒的.css文件添加到AppAssets
中 vendor/font-awesome/css/font-awesome.min.css
添加前端和后端AppAssets
frontend->资产 - > 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-&GT;资产 - &GT; 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',
];
}
?>
感谢高级.....
答案 0 :(得分:1)
您可以创建新的资产文件并将其包含在布局
中class FontAwesomeAsset extends \yii\web\AssetBundle
{
public $sourcePath = '@vendor/font-awesome/';
public $css = [
'css/font-awesome.min.css',
];
public $depends = [
'yii\web\YiiAsset',
];
}
然后在你的布局文件中调用它(通常是views / layout / main.php)
frontend\assets\FontAwesomeAsset::register($this);
答案 1 :(得分:0)
供应商文件夹无法通过网络访问。一种解决方案是将css,js,img从vendor文件夹符号链接到web文件夹。然后包括那个。或者这是Yii的方法:
例如:
Awareness.FenceApi.updateFences(
getGoogleApiClient(),
new FenceUpdateRequest.Builder()
.addFence(
"something",
HeadphoneFence.unplugging();,
createSendHeadphoneUnpluggedMessagePendingIntent(context))
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if(status.isSuccess()) {
Log.i(TAG, "Headphone unplugged fence was successfully registered.");
} else {
Log.e(TAG, "Headphone unplugged fence could not be registered: " + status);
}
}
});
或者不要试试这个
<?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',
];
}
答案 2 :(得分:0)
首先使用代码
创建新的资产文件[vendorName]资产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 = [
];
}
接下来将此文件添加到主资产$ depends:
public $depends = [
..
'frontend\assets\[vendorName]Asset',
..
];
这就是全部