laravel中css,js等静态文件的位置在网站的根目录public下,但是我想把文件放在别的目录下,比如:resoures/assets,在入口文件public/index.php中添加了如下代码:
$app = require_once __DIR__.'/../bootstrap/app.php';
/*
* 设置静态文件目录
*/
$app->bind('path.public', function() {
$path_public = base_path() . DIRECTORY_SEPARATOR . env('PATH_PUBLIC', 'public');
return $path_public;
});
我在.env文件中设置了环境变量:
PATH_PUBLIC=resources/assets
使用帮助函数public_path()打印出来的结果的确改变了,为:网站根目录/resources/assets,接下来我在这个目录下新建了styles目录,并在视图中引用:
<link rel="stylesheet" href="{{ asset('styles/login.css') }}">
<link rel="stylesheet" href="<?php echo asset('styles/login.css') ?>">
解析后网页源代码是这样的:
<link rel="stylesheet" href="{{ asset('styles/login.css') }}">
<link rel="stylesheet" href="http://www.cx.com/styles/login.css">
为什么{{}}不解析?要添加smarty扩展?为什么静态文件链接没有变/resources/assets?
引入一个css都这么难么。。。我要跳黄河。。。求解答。
写个绝对路径不就行了