Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

cakePHP Convention

In cakePHP we need to follow some rules defined by cake framework.we will go through this convention.First,we need to how to create,named Model,view , Controller and tables. it also provides global constants and functions.

Model Creation and Convention:

Convention:
1.Model Class name should be singular and CamelCased(i.e every first letter of every word should be in upper case).Example: User,OnlineUser.


2. Model class page be 'user.php' or 'online_user.php'

3. This class file will be reside inside 'site_folder'->app->models



Syntax:
class User extends AppModel{
}

AppModel Class is defined inside the core cake directory.Model is related with table name.Each model has its associate table.one thing you need to remember that when you are creating a new table you also have to maintain some convention.


Table name Convention:

Table name will be plurals of its model name.

For 'User' model table name will be 'users' and OnlineUser table name will be online_users.



Controller Creation and Convention

Syntax:

Controller extends AppController {
function index(){
}

function signup(){
}
}

?>

Convention:
1. Controller Class name should be plural and CamelCased(i.e every first letter of every word should be in upper case) and end with 'Controller' Keyword.Example: UsersController,OnlineUsersController.

2.
Controller class page will be 'user_controller.php' or 'online_users_controller.php'

3. This class file will be reside inside 'site_folder'->app->controllers



View Creation and Convention:

Convention:

1. View are actions names of it controller. for example UsersController has two action i.e:index and signup then it view files name will be index.thtml and signup.thml. Extension of these files may be .ctp.

2. These files will reside inside 'site_folder'->app->views.

3. For user you need to define a folder with plurals form inside view directory and inside this directory you need to save those view files.
i.e:'site_folder'->app->views->users.


We will discuss global constant and global functions later







This post first appeared on Cakephp For Beginners To Advanced, please read the originial post: here

Share the post

cakePHP Convention

×

Subscribe to Cakephp For Beginners To Advanced

Get updates delivered right to your inbox!

Thank you for your subscription

×