简体   繁体   English

用于引导字体的 Yii2 BaseUrl

[英]Yii2 BaseUrl for bootstrap fonts

I need your help guys.我需要你们的帮助。 I changed directory for all Assets.我更改了所有资产的目录。 It works properly, but not for bootstrap fonts.它工作正常,但不适用于引导字体。

For Ex: path for css and js file now is project/www/web_assets/all.css and Yii2 found them properly.例如:css 和 js 文件的路径现在是project/www/web_assets/all.css并且 Yii2 正确找到了它们。

But it does not working for fonts.但它不适用于字体。 Yii2 is looking for fonts at wrong derictrory /var/www/tt_yii/web/assets/582582f3/fonts/glyphicons-halflings-regular.woff2 . Yii2 正在寻找错误的字体/var/www/tt_yii/web/assets/582582f3/fonts/glyphicons-halflings-regular.woff2

Bootstrap gets used at different places. Bootstrap 在不同的地方使用。 It is already configured by default by the BootstrapAsset and is a dependency for other pre-defined assets.默认情况下, BootstrapAsset已经配置了它,并且是其他预定义资产的依赖项。 But you can override the default location.但是您可以覆盖默认位置。

Assuming you have the same file structure in web_assets as it can be found in 'vendor/bower-asset/bootstrap/dist' (contains folder css, fonts and js) you can add the following to your components configuration:假设您在web_assets文件结构与“vendor/bower-asset/bootstrap/dist”(包含文件夹 css、fonts 和 js)中的文件结构相同,您可以将以下内容添加到组件配置中:

use yii\bootstrap\BootstrapAsset;

...

'components'          => [
   ...
    'assetManager' => [
        'bundles' => [
            BootstrapAsset::class => [
                'sourcePath' => null,
                'baseUrl'    => '@web/web_assets',
            ],
        ]
    ],
    ...
],

@web points to the web folder where the index.php and your web_assets directory file should exist as well. @web指向 web 文件夹,其中 index.php 和您的web_assets目录文件也应该存在。 sourcePath gets set to null since baseUrl wouldn't be evaluated. sourcePath被设置为 null,因为 baseUrl 不会被评估。

Further information about configuring the used bundles can be found at AssetManager::$bundles or in the guide .有关配置使用的包的更多信息可以在AssetManager::$bundles指南中找到

Similar question is here .类似的问题是here

Check you nginx settings.检查你的nginx设置。 If there is a filetype list, you should insert these font types into it also:如果有文件类型列表,您还应该将这些字体类型插入其中:

location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|svg|ttf|woff|woff2)$

(Duplicate of bootstrap icon fonts not loading ) 未加载引导程序图标字体的重复项)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM