CakePHP 2.0 Naming Conventions

The PHP’s popular Framework has some Naming conventions that need to be followed at the time of development.

Controller Conventions

Controller class names are plural, CamelCased, and end in Controller and the filename would be ‘ApplesController.php’.

e.g. PeopleController and LatestArticlesController

File and Class Name Conventions

In general, filenames match the class names, which are CamelCased. So if you have a class MyNiftyClass, then in CakePHP, the file should be named MyNiftyClass.php. Below are examples of how to name the file for each of the different types of classes you would typically use in a CakePHP application:

  • The Controller class KissesAndHugsController would be found in a file namedKissesAndHugsController.php
  • The Component class MyHandyComponent would be found in a file named MyHandyComponent.php
  • The Model class OptionValue would be found in a file named OptionValue.php
  • The Behavior class EspeciallyFunkableBehavior would be found in a file namedEspeciallyFunkableBehavior.php
  • The View class SuperSimpleView would be found in a file named SuperSimpleView.php
  • The Helper class BestEverHelper would be found in a file named BestEverHelper.php

Each file would be located in the appropriate folder in your app folder. Continue reading