Archive for เมษายน 2008
MissingController in CakePHP if file with same name exists in root
Just found out that you can get a MissingController error from CakePHP if you have a file with the same name as the controller file in the root directory.
E.g. If you have a controller called CompanyInfosController (in /app/controllers/company_infos_controller.php), and you also have another file called /company_infos.php.
When this condition occurs, instead of $html->link(‘title’, ‘/company_infos’) calling the CompanyInfosController class action, it seems the framework does a redirect to the controller called RedirectController instead.
Haven’t looked into the code, dunno why.
Fixing CakePHP Tutorial 403/404 problems in Leopard
In case your newly created CakePHP site looks weird without any styling, try enabling the mod_rewrite (see “8.5 A Note on mod_rewrite“).
You might get a 403 Forbidden error when changing the AllowOverride directive to all. If you get one, open the Console and see Apache’s error log. It might be because you haven’t added FollowSymLinks option. Try adding that and the configuration should look something like:
<Directory “/Users/John/Sites/cake”>
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Now, if everything works fine after that, cool. If you’re getting a 404 Not Found error saying something like:
The requested URL /Users/John/Sites/cake/app/webroot/ was not found on this server.
Chances are because you’re using Web Sharing in Leopard and your site is located in your <home>/Sites directory. If that’s so, try adding the RewriteBase directive to your .htaccess file in Cake’s root directory. The file should now look something like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /~John/cake
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Hopefully that’ll fix the problem.