【发布时间】:2016-11-27 12:31:14
【问题描述】:
社区成员!我想在这里向您提出一个问题:在Yii2框架中使用css样式和js脚本需要询问应用程序有机会使用它们的所谓资源包。如何处理图像?我不明白如何访问使用它们..
这就是资源包的意思:(这个文件AppAsset.php)
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
'css/bootstrap.min.css',
'css/bootstrap-social-gh-pages/bootstrap-social.css',
'css/flexslider.css',
'css/ie10-viewport-bug-workaround.css',
'css/justified-nav.css',
'css/font-awesome-4.6.3/css/font-awesome.css',
];
public $js = [
'scripts/ie-emulation-modes-warning.js',
'scripts/jquery.flexslider-min.js',
'scripts/modernizr.js',
'https://code.jquery.com/jquery.min.js',
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
所以,这里会抛出 403 错误:
<div class="col-lg-2 col-md-2 col-sm-3 col-xs-12">
<img src="<?= Yii::$app->request->baseUrl ?>/img/logo2.png" style="width: 100%;">
</div>
【问题讨论】:
-
不需要将引导程序添加为单独的 css 和 js 文件,因为您已经将
BootstrapAsset添加为依赖项。状态 403 表示服务器拒绝继续此请求(禁止)。可能需要设置文件夹权限。 -
是的,关于引导程序,我理解,正确。但是如何打开对任何带有图像的目录的访问?目前这个应用程序在我的本地服务器上。
-
使用
<?= Yii::$app->request->baseUrl ?>/img/logo2.png时在HTML源代码中显示什么URL?可以直接在浏览器中打开这个网址吗? -
http://basic/web/img/logo2.png- 这是正确的网址 -
所以如果地址是正确的并且你可以直接在浏览器中访问它意味着它不是资产和图像的问题,还有其他原因。
标签: php frameworks yii2