codeofaninja
website

CakePHP Naming Conventions

Photo of Mike Dalisay
Modified Monday, September 20, 2010
by - @ninjazhai
CakePHP requires us to follow certain convention. In this way, we will have very uniform system development, have free functionality, and save time over tracking configuration files! :)

1. Create a Model 
  • directory: app/models/
  • filename: post.php 
  • classname: Post
  • extension: class Post extends AppModel
The filenames of models are always singular. And its classnames are CamelCased.
2. Create a Controller 
  • directory: app/controllers/
  • filename: posts_controller.php
  • classname: PostsController
  • extension: class PostsController extends AppController
The filename of a controller is always plural followed by an underscore then the word "controller" (_controller). Classnames are also CamelCased.
3. Creat a View
  • directory: app/views/posts/
  • filename: hello_world.ctp
You will create another view directory for each of your models. In this case, we created a directory called "posts" under app/views/ directory. Filenames are saved with the extension .ctp (I believe its "cake template page"). They are also named after the method/function (action) inside your controller.
If you have more than one word object (ex. Sponsored Member), you may use underscores to name it. In my case, I will name it "sponsored_member".


Model: sponsored_member.php
View: app/views/sponsored_members
Controller: sponsored_members_controller.php

For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
 
 
Fundamentals
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.