Cake Conventions

by 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();

Report

More on General Interest

Advertising

Comments

  • powtac posted on 11/26/09 04:01:13 PM
    Is it allowed to use "-" in table names?
  • powtac posted on 06/25/09 09:52:28 AM
    I created a list of protected class/table names for CakePHP 1.2:

    app
    appcontroller
    appmodel
    behaviorcollection
    cache
    cacheengine
    cakelog
    cakesession
    classregistry
    component
    configure
    connectionmanager
    controller
    datasource
    debugger
    dispatcher
    file
    fileengine
    folder
    helper
    inflector
    model
    modelbehavior
    object
    overloadable
    overloadable2
    router
    security
    sessioncomponent
    set
    string

    See http://groups.google.com/group/cake-php/msg/8d149a246d46d3cf
  • JaceX posted on 04/27/09 02:45:38 AM
    Whenever I see a cake I remember happy celebrations, like birthdays, wedding, and other social gatherings. Some might affort to have parties with their own expenses or might avail loans to have one. Of all the things to get a personal loan for, one of them is NOT an ancient piece of wedding cake. Almost straight out of Seinfeld, someone bought a piece of wedding cake from the wedding of Princess Louise, daughter of Queen Victoria. They didn't pay too much for it – only about £150, or about $220, so they probably won't need mortgage loan modification due to putting their house on the block for a 200-year-old piece of cake. Well for me, having loans are privilege so use it wisely.
    LINK TO READ:http://personalmoneystore.com/moneyblog/2009/04/16/princess-louise-wedding-cake/
  • Kavi posted on 03/21/09 05:12:10 AM
    I want know how to use cakphp in our application.
  • mafo posted on 11/11/07 03:07:13 PM
    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
  • bazil749 posted on 11/04/07 01:35:23 AM
    A column named "name" will be used by the GenerateList() function in a drop down list or multiple select.
  • jttacj1 posted on 07/14/07 02:31:01 PM
    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.
login to post a comment.