Simple registration in CakePHP

Suppose that there is a users table in recipe_db database.


In users table we will save a user data using cakephp. Let create a controller name usersController :

class UsersController extends AppController{</pre>
public function add(){
 $this->Session->setFlash('Email Address is already used,Plesae try again');
 $this->request->data['User']['id']= uniqid();
 if($this->User->save($this->request->data)) {
 $this->Session->setFlash('Successully save your information!!');
 $this->Session->setFlash('Unable to save your Information!!');


this add() of  UsersController class will insert users information into db table users. Corresponding view of this add action of users controller will be into a Users folder , and name it as add.ctp .

<?php echo $this->Form->create(); ?>
 <legend>Add New User</legend>
 echo $this->Form->input('name',array('required'=>'required'));
 echo $this->Form->input('email',array('required'=>'required','type'=>'email'));
 echo $this->Form->input('country',array('options'=>array(
 'pakistan'=>'Pakistan' ,
 echo $this->Form->input('password',array('required'=>'required'));
 echo $this->Form->input('Confirm password',array('type'=>'password'));
 echo $this->Form->end('Save');

To validate user input we will add some validation script in User model.

class User extends AppModel{
 //put your code here
 public $validate=array(
 'message'=>'Input your name'
 'message'=>'Input a valid emial address'
 'message'=>'Input your email address'


 'alphaNumeric' => array(
 'rule' => 'alphaNumeric',
 'required' => true,
 'message' => 'Alphabets and numbers only'
 'password' => array(
 'rule' => array('minLength', '8'),
 'message' => 'Minimum 8 characters long'


Software Engineer at The Jaxara IT Ltd , Dhaka , Bangladesh

Tagged with: , , ,
Posted in CakePHP
2 comments on “Simple registration in CakePHP
  1. sj says:

    really helpful..thankxxx

  2. mandeep says:

    please send me user login ,registration ,edit user information ,display user information,find user data from table in cakephp 3.2 with coding on my mail.please urgently required me my gmail

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: