CakePHP 未输出正确的 CSS 路径
刚刚开始使用 CakePHP 进行开发,安装并配置它。但是,应用程序不会输出样式表的正确路径。
查看页面源代码时,样式表的路径为:
/rm-lab/css/cake.generic.css
这会导致 404 错误页面。
如果我尝试通过此路径访问样式表,则会加载样式表;
/rm-lab/app/css/cake.generic.css
感谢您的帮助。
更新: 在尝试了多种解决方案之后,我刚刚在另一个子文件夹中全新安装了 cakePHP,这可以很好地加载 CSS。我认为这与 .htaccess 文件有关。
Just started developing in CakePHP, installed it and configured it. However the application doesn't output the correct path to the stylesheet.
When viewing the source of the page the path to the stylesheet is:
/rm-lab/css/cake.generic.css
This leads to 404 error page.
The stylesheet loads if I try to access it through this path;
/rm-lab/app/css/cake.generic.css
Appreciate the help.
UPDATE:
After trying numerous solutions, I just did a fresh install of cakePHP in another subfolder and this loads the CSS fine. I think it was to do with the .htaccess files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的蛋糕应用程序似乎位于子文件夹中。您应该在 app/webroot 中的 .htaccess 文件中设置重写基础
在 app/webroot/.htaccess 中,添加以下行:
您的 .htaccess 文件现在应如下所示:
It appears that your cake app is in a subfolder. You should set the rewrite base in your .htaccess file in app/webroot
In app/webroot/.htaccess, add the following line:
Your .htaccess file should now appear as such:
您使用主题吗?如果是这样,您可能需要切换路径。请参阅此处(向下滚动一点):
http://book.cakephp.org/view/1093/主题
Are you using a theme? If so, you might need to switch the path. See here (scroll down a bit):
http://book.cakephp.org/view/1093/Themes
从我的角度来看,这似乎是一个 Apache 级别的问题。 Apache 中的 DocumentRoot 是否设置为 /app 目录?这肯定会有帮助。一般来说,我认为您应该使用 Cake 检查 Apache 的内容(查看应用程序中的 .htaccess 文件)。为了查明问题,我将 CakePHP 配置为不在 core.php 中使用 mod_rewrite。
Off the top of my head, this seems like an Apache-level problem. Is your DocumentRoot in Apache set to the /app directory? This would definitely help. In general, I think you should examine the Apache stuff with Cake (look at your .htaccess files in the app). To pinpoint the problem, I would configure CakePHP to not use mod_rewrite in core.php.
尝试在 public_html 文件夹中创建一个名为“test_rewrite.php”的新脚本
访问该文件以确保您的共享主机帐户上启用了 mod_rewrite。如果未加载,您可能需要联系您的托管提供商以启用它。
Try making a new script in your public_html folder called "test_rewrite.php"
Access the file to make sure that mod_rewrite is enabled on your shared hosting account. If it's not loaded, you may want to contact your hosting provider to enable it.
我认为您正在尝试使
HtmlHelper::css
方法执行不应执行的操作。根据文档:cake.generic.css
文件确实应该使用$this->Html->css(' 放置在
您在视图中使用的代码。app/webroot/css
文件夹中cake.generic')以下是 API 文档的链接:HtmlHelper 类文档
I think you are trying to make the
HtmlHelper::css
method do something that it isn't supposed to do. According to the documentation:The
cake.generic.css
file should indeed be placed within theapp/webroot/css
folder using the$this->Html->css('cake.generic')
code that you are using in your view.Here's a link to the API documentation: HtmlHelper Class documentation
确保您的 apache DocumentRoot 设置为 /path/to/your/site/in/a/subdir/webroot
webroot 部分至关重要 - 它阻止访问 webroot 外部的文件,并且 webroot 文件夹中的 htaccess 会跳过加载为 webroot 内的实际文件(img、css 等)调度 index.php 文件
如果您正确设置了 DocumentRoot 路径,并且从站点文件夹的根目录到 cake 安装的子文件夹包含在 .htaccess 中如上所述,文件路径问题应该会自行解决。
您可能想让我们知道蛋糕安装在服务器上的绝对路径,并向我们展示包含 DocumentRoot 详细信息的 VirtualHost 块。
Make sure your apache DocumentRoot is set to /path/to/your/site/in/a/subdir/webroot
The webroot part is critical - it prevents files from outside the webroot from being accessible and the htaccess in the webroot folder skips loading the dispatch index.php file for actual files inside the webroot (img, css, etc)
If you have the DocumentRoot path set right and the subfolder from the root of the site folder to the cake install is included in the .htaccess file as mentioned above the pathing issue should fix itself.
You might want to let us know the absolute path on the server to the cake install as well as show us the VirtualHost block with the DocumentRoot details.