CakePHP conventions

CakePHP is a rapid development framework for PHP. As Symfony, it’s also based on the MVC model and but much lite and easier to learn when compared with Symfony. The following are the common conventions for CakePHP:

  • table names are plural and lowercased
  • model names are singular and CamelCased: ModelName
  • model filenames are singular and underscored: model_name.php
  • controller names are plural and CamelCased with *Controller* appended: ControllerNamesController
  • controller filenames are plural and underscored with *controller* appended: controller_names_controller.php
  • associations should use the ModelName, and the order should match the order of the foreignKeys: var $belongsTo = ‘User’;
  • foreign keys should always be: table_name_in_singular_form_id: user_id (foreign key) → users (table)
  • many-to-many join tables should be named: alphabetically_first_table_plural_alphabetically_second_table_plural: tags_users
  • columns in many-to-many join tables should be named like other foreign keys: tag_id and user_id
  • columns named “created” and “modified” will automatically be populated correctly
September 28th, 2007 @ 10:53 AM • Filed under CakePHP