In this post explains, how to implement CRUD operations in CakepPHP 2.x version. we are using Cakephp 2.9.3v. First download the cakephp 2.9.3v source files from Github here. Its useful for a beginner to start cakephp.
We aren’t implement jquery validations and datatable too. We use only default cakephp libraries to validate the user’s input with bootstrap 3. We use most of form fields and cover all possible cases to validate it.
See our demo video on Youtube:
Cakephp folder structure is same as other frameworks but difference in assets folder.
Download cakephp version from here.
Setup Basic Configuration settings in app/config.
To update CakePHP Debug Level in config/core.php
0: No error messages, errors, or warnings shown. Flash messages redirect.
1: Errors and warnings shown, model caches refreshed, flash messages halted.
2: As in 1, but also with full debug messages and SQL output.
To update security salt with security hashing methods in config/core.php
Update your database connection settings in config/database.php
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'HOSTNAME',
'login' => 'YOUR_USERNAME',
'password' => 'YOUR_PASSWORD',
'database' => 'YOUR_DATABASE_NAME',
'prefix' => '',
'encoding' => 'utf8',
For a mail settings to rename email.php.default file to email.php and get a backup of email.php.default file.
Custom url rewriting and also we can able to add define constants variables to access globally in config/routes.php
Setup controller file Controller/AppController.php
update your helpers/components functions if needed.
Create a controller
class UsersController extends AppController
public $helpers = array('Html', 'Form', 'Flash');
public $components = array('Flash');
public $uses = array('User', 'Country', 'State', 'City'); //tables are uses
in this controller.
public function index()
$this->paginate = array(
'conditions' => array('status' => '1'),
'limit' => 3,
'order' => array('id' => 'desc')
$users = $this->paginate('User');
$this->set uses to get the results from controller to view file.
we can multiple values in array too.
$data = array(
'user_id' => $user_id,
'username' => $username,
'result' => $results
Create a sample model file
class Country extends AppModel
var $name = "Country";
var $name = TABLE_NAME;
View folder has Elements, Email, Errors, Helper, Layouts, Pages, and Scaffolds these are the basic folders are generated while installation of cakephp.
In this folder, we move common files like header, footer and sidebar files to access those files in globally.
If you want to create a custom file means, create a folder for it named it as module name like “Users”.
Inside this folder create add.ctp file. In cakephp we have to save all the view files are “.ctp” format.
Now we have implemented CRUD functionalities by using AdminLTE theme.
Source code: Download from Github Here