CakePHP naming conventions

CakePHP naming conventions FAQ: Can you share some examples of the CakePHP naming conventions, specifically the CakePHP model, view, and controller naming conventions?

As I get back into the CakePHP development world, I wanted to make a little CakePHP naming conventions reference page, showing examples of the standard CakePHP naming conventions for CakePHP model, view, and controller elements.

CakePHP naming conventions for an "orders" table

Assuming we have a database table named orders, the following standard CakePHP naming conventions should be used:

Model
  filename  = order.php
  classname = Order
  directory = app/models

View
  filename  = (same as the action name in the controller)
  extension = .ctp (the filename extension)
  directory = app/views/orders

Controller
  filename  = orders_controller.php
  classname = OrdersController
  directory = app/controllers

CakePHP naming conventions for an "order_items" table

Assuming we have a database table named order_items, the following standard CakePHP naming conventions should be used:

Model
  filename  = order_item.php
  classname = OrderItem
  directory = app/models

View
  filename  = (same as the action name in the controller)
  extension = .ctp (the filename extension)
  directory = app/views/order_items

Controller
  filename  = order_items_controller.php
  classname = OrderItemsController
  directory = app/controllers

Standard CakePHP controller actions and view names

Standard CakePHP scaffolded controller actions have these names:

index()
add()
edit()
view()
delete()

Creating an action in a controller that has one of these names will replace the scaffold action for that name.

These standard scaffold controller actions will correspond to view files with these names:

index.ctp
add.ctp
edit.ctp
view.ctp
delete.ctp

I hope this CakePHP naming conventions reference page has been helpful. I'll try to remember to keep coming back here to update this page as I work with more CakePHP elements, including model, view, controller, helpers, components, elements, layouts, behaviors, and data sources. If you can think of any CakePHP naming conventions that would be helpful to include here, just leave a note in the Comments section below.