Just started developing in CakePHP, installed it and configured it. However the applica开发者_如何学编程tion 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.
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:
RewriteBase /rm-lab
Your .htaccess file should now appear as such:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /rm-lab
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
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
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.
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.
<?php
if (in_array("mod_rewrite", apache_get_modules())) {
echo "mod_rewrite loaded";
} else {
echo "mod_rewrite not loaded";
}
?>
I think you are trying to make the HtmlHelper::css
method do something that it isn't supposed to do. According to the documentation:
(mixed $path required) -- The name of a CSS style sheet or an array containing names of CSS stylesheets. If $path is prefixed with '/', the path will be relative to the webroot of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
The cake.generic.css
file should indeed be placed within the app/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
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.
精彩评论