Professional Documents
Culture Documents
Introduction
MVC
CakePHP folder:
App
Cake {The core/libraries file of cake is here}
Vendor {3rd party PHP libraries is here}
.htaccess
index.php
README
Model
Plugin
Contain for sub application to support main application. This folder same
like other app folder cakephp.
View
Presentation(display) file and other file replace here: elements, errors pages,
helpers, layouts, email template and view files
Webroot
This folder as documents root folder for your application. Folder here also
server as holding places for CSS, Images, Script file, Uploaded Files.
INTRODUCTION OF CAKEPHP
Mohamad Zaki mohdzaki04@gmail.com
Cakephp Conventions
Cakephp Conventions takes a bit of time to learn and implementation. Convention also makes for a
very uniform system development, allowing other developers to jump in and help more easily.
CakePHP have its own naming convention standards to be used during PHP application
development. Whenever you have to create application using CakePHP you will need to create
following files first.
So, while creating above files you will have to follow CakePHP naming convention standards. And
its very important to the PHP developer to follow these standards.
A) Database table and field naming convention
Table name must be in lowercase & plural. If there are more than one word in the table
name then words should be separated by underscore.
Example : users, consultant_services, etc.
Field-Name should also be in lowercase and if more than one word then separated by
underscore.
Example : id, consultant_service_name
INTRODUCTION OF CAKEPHP
Mohamad Zaki mohdzaki04@gmail.com
Model file names are upper camel case, more than one word should be separated by
underscore.
Example : User.php or Consultant_service.php
Model class name are singular, usually this should be the database table name but in singular
format.
Example : User or ConsultantService
EXAMPLE 1:
Path : /app/Model/User.php
Coding Content:
class User extends AppModel {
public $name = 'User';
}
EXAMPLE 2:
Path : /app/Model/User_profile.php
Coding Content:
class UserProfile extends AppModel {
public $name = 'UserProfile';
}
Controller file names are plural and upper camel case, and filenames also end with
Controller.php.
Example : UsersController.php or ConsultantservicesController.php
EXAMPLE 1:
Path : /app/Controller/UsersController.php
Coding Content:
class UsersController extends AppController {
}
EXAMPLE 2:
Path : /app/Controller/UserProfilesController.php
Coding Content:
class UserProfilesController extends AppController {
}
INTRODUCTION OF CAKEPHP
Mohamad Zaki mohdzaki04@gmail.com
Multiple word controllers can be any inflected form which equals the controller name so:
View files are located at /app/views and into that a folder is created with its respective
controller name, if more than one word then separated by underscore.
View file names are function_name.ctp (The function name is the name of the function you
have defined in your appropriate Controller file.)
EXAMPLE 1:
Path : /app/View/Users
Function name in UsersController.php
class UsersController extends AppController {
function index(){
....
}
}
EXAMPLE 2:
Path : /app/View/UserProfiles
Function name in UsersController.php
class UserProfilesController extends AppController {
function index(){
....
}
}
Components
Path : /app/Controller/Component
Name camelcased: GoogleTranslateComponent filename: google_translate.php
Helpers
Path : /app/View/Helper
Name camelcased: GoogleHelper filename: google.php
INTRODUCTION OF CAKEPHP
Mohamad Zaki mohdzaki04@gmail.com
Cakephp Configuration
{
array(
=> 'Database/Mysql',
=> false,
=> 'localhost',
=> 'cakephpuser',
=> 'c4k3roxx!',
=> 'my_cakephp_project',
=> ''
Configure
Use write() to store data in the applications configuration:
Configure::write('Faculty.name','Computer Sains');
Configure::write('Company.code','CSXXXX');
Routes Configuration
Routes in an application are configured in app/Config/routes.php
Default Routing
URL pattern default routes:
http://example.com/controller/action/param1/param2/param3
The URL /posts/view maps to the view() action of the PostsController, and
/products/view_clearance maps to the view_clearance() action of the
ProductsController. If no action is specified in the URL, the index() method is
assumed.
INTRODUCTION OF CAKEPHP
Mohamad Zaki mohdzaki04@gmail.com
The default routing setup also allows you to pass parameters to your actions using
the URL. A request for /posts/view/25 would be equivalent to calling view(25) on
the PostsController.
Default Example:
Controller
Action
Param
URL
UsersController
index()
null
/users/index
/users/
UsersController
view(param)
132
/users/view/123
Custome Example 1:
Router::connect(
'/senarai_pengguna/',
array('controller' => 'users', 'action' => 'index')
);
Custome Example 2:
Router::connect(
'/maklumat_pengguna/*',
array('controller' => 'users', 'action' => 'index')
);
Controller
Action
Param URL
UsersController
index()
null
/users/senarai_pengguna/
/users/senarai_pengguna/index
UsersController
view(param)
132
/users/maklumat_pengguna/123
Model
HasMany, BelongTo, Validation
Helpers
Form Helpers
HTML Helpers
CSS, Script Helpers
Number Helper