Conventions used in Cake

Or “Folk Wisdom of the Old People.”

Collected (after prodding by plemieux at the IRC) and described. Let’s get some structure here.

Database conventions

Tablenames in plural.

Relationship tables have their tablenames in alphabetical order (categories_products, not products_categories).

A table needs > 1 field. (That should be database common sense, but here it is, in writing.)

Magical field names in tables:

Field Datatype Notes
id INT Needs AUTO_INCREMENT (MySQL), or equivalent in other DBMSes. Identity field.
created DATETIME When the row is created by Cake, this gets set to the current timestamp.
modified DATETIME When the row is updated by Cake, this is set to current timestamp.
[anothermodelname]_id INT Foreign key. For example: category_id, person_id, city_id

See also Cake Manual

Unsupported & unimplemented

ENUM and SET, the database field datatypes, are not supported by Cake scaffolding, but appears to work with Cake active records.

Some aspect to clarify (2006/01/10 by plemieux, and 2006/01/11 by olleolleolle)

  • Confirm previous assertion on ENUM and SET
  • Is there any positive or negative effect in using underscores in fieldnames? (E.g. level_of_nastiness)

Model conventions

Singular names.

To make Model work with PHP4, set its name explicitly (a good practice on PHP5, too):

var $name = "Modelname";

To use underscores in tablenames (that are not relationship tables):

  var $useTable = "user_profiles";

Scaffolding

DATETIME fields named created or modified will not be shown in Scaffolded forms.

(You want the form to show the date? Name the field something else, like updated, which will have the label Modified when viewing it.)

Unit testing conventions

All test cases should have the file suffix ‘.test.php’.
Example: controller.test.php

All group tests should have the file suffix ‘.group.php’.
Example: controller.group.php

Cake development conventions

(Not Coding Conventions.) So you have an inkling why things happen the way they do. See: Coding standards for Cake

Cake is developed primarily for MySQL. Other DBMSes get supported later. Contributions are very welcome.

 
docs/cake_conventions.txt · Last modified: 2006/01/25 04:53 by olle