0.10 Dev Gotchas!

Note: This page is quite old. — Olle Jonsson 2005/12/12 10:24

These are the things that might hit you when you first install Cake or upgrade from an older version.

Cake home page not displaying properly (Where is the CSS)

Problem: mod_rewrite not enabled.

Solution: Edit line 45 of Cake /app/config/core.php file, and uncomment the line

define ('BASE_URL', $_SERVER['SCRIPT_NAME']);

If you have mod_rewrite and prefer to use CakePHP pretty URLs you also have to remove the .htaccess files.

These are located in:

unpacked directory/.htaccess

unpacked directory/app/.htaccess

unpacked directory/app/webroot/.htaccess

Fatal error: Class 'AppController' not found

Fatal error: Class ‘AppController’ not found in /Library/WebServer/Documents/cake/cake/dispatcher.php on line 105.

Problem: Usage of oldstyle ?url= urls.

Solution: Change the style of url from /cake/index.php?url=controller/action to /cake/index.php/controller/action.

Security Alert! The PHP CGI cannot be accessed directly.

This error will occur if you’re running PHP as a CGI process. While the problem lies with the server, if you are unable to change the configuration of the server there is a solution which involves editing cake, ticket 66 documents the problem and solution.

To solve:

// In cake/index.php 
$elements = explode('/index.php?url=',$uri);
 
// In core.php
define('BASE_URL', $_SERVER['PATH_INFO'].'?url=');

Where are app_controller and app_model

These files were moved to the core. If you want to override them create them inside of your /app

Fatal Error: Class cannot inherit

Problem: Fatal error: Class pagescontroller: Cannot inherit from undefined class pageshelper

Solution: be sure that your controller is extending AppController.

Where do my helpers go?

In version 0.9.1 Cake had “Controller Helpers” – which means that a Controller called MyController extended MyHelper. This was changed in 0.10.0.

Your controllers should now extend AppController.

So, Helpers have taken on a new function. They are used to aid your View now. If your controller still needs help you can create a component.

What about my layout? There are no files for that!

You can override the Cake core layout by creating a directory at /app/views/layouts, and fill it with layout templates.

What should my Controller extend?

What should my Model extend?

Differences between Vendors, Components and Helpers?

Go to Extending Cake tutorial to learn the differences.

How to pass empty parameters to a Cake URL

Ticket 28: Empty parameters in actions are not handled correctly

If you wish to call a cake action using an empty parameter, rather than doing /mycontroller/myaction//2/3 you should insert some form of fake parameter - for example /mycontroller/myaction/void/2/3 (here the word void which will be passed to your action as a string value represents an empty parameter - your action should check for this and URLs should be constructed with the word void where an empty value exists).

Method not found

This can be due to the Model not having its $name set. Set that to the name of the model class, for the model Product, it is:

class Product extends AppModel 
{
   $name = "Product"; 
}

Problems with radioTags

If you are using radioTags and noticing errors...

Problem: Tag Template for radio input has improper format.

Solution: Open tags.ini.php - Change line 60 (or whatever line the radio tag template is on to:

radio = "<label for="%s"><input type="radio" name="data[%s][%s]" id="%s" %s />%s</label>"

Flash?

Do not use Controller::flash methods now - you are better off using the Session::setFlash().

Production file layout: php warnings

Problem: In version 0.10.8.2047, if you use production file layout as recommended in manual (http://manual.cakephp.org/pages/ch03s03), you get warnings from dispatcher.php:baseUrl().

Solution: Open cake/dispatcher.php, go to baseUrl() method and escape the directory separator characters in APP_DIR and WEBROOT_DIR constants used in preg_match() calls. See below:

	$appDir = str_replace(DS, '\\'.DS, APP_DIR);
	$webrootDir = str_replace(DS, '\\'.DS, WEBROOT_DIR);

Now use $appDir and $webrootDir in preg_match() lines in baseUrl() method

 
docs/0.10_dev_gotchas.txt · Last modified: 2006/02/20 22:43 by bijoy