Cake Conventions

By Tamas Amon (sajt)
This is the Cake Conventions from the old wiki site.
  1. tables names are plural and lowercased
  2. model names singular and CamelCased: ModelName
  3. model filenames are singular and underscored: model_name.php
  4. controller names are plural and CamelCased with *Controller* appended: ControllerNamesController
  5. controller filenames are plural and underscored with *controller* appended: controller_names_controller.php
  6. associations should use the ModelName, and the order should match the order of the foreignKeys: var $belongsTo = 'User';
  7. foreign keys should always be: table_name_in_singular_form_id: user_id (foreign key) -> users (table)
  8. many-to-many join tables should be named: alphabetically_first_table_plural_alphabetically_second_table_plural ie: tags_users
  9. columns in many-to-many join tables should be named like other foreign keys ie: tag_id and user_id
  10. columns named created and modified will automatically be populated correctly
  11. components should be CamelCased: MyComponent : my_component.php : var $components = array('MyComponent'); $this->MyComponent->method();
  12. helpers should be CamelCased: MyHelper: my_helper.php: var $helpers = array('MyHelper'); $myHelper->method();

 

Comments 201

CakePHP Team Comments Author Comments
 

Comment

1 An Undocumented Convention

I accidentally discovered a CakePHP convention that I have not been able to find in the documentation:

A column named "name" or "title" will automagically be used as the description for a foreign key in scaffolding or a baked view.
Posted Jul 14, 2007 by James
 

Comment

2 1 More Convention

A column named "name" will be used by the GenerateList() function in a drop down list or multiple select.
Posted Nov 4, 2007 by Baz L
 

Question

3 view using many controllers

Hi, i'm new in cakePHP and I want to know what's the convention to make a view that uses more than 1 controller. I mean, i have a view that shows a list of messages and a list of events. Where should I put the view? in wich folder?


thanx
Posted Nov 11, 2007 by Tiago Piccinin