Flipkart

Tuesday, September 15, 2009

Sample Cake PHP Application

Controller
----------------------
data)) {
$user_check['email'] = $this->data['User']['email'];
$user_check['password'] = $this->data['User']['password'];
$users = $this->User->find($user_check);
if(isset($users['User']['id'])) {

$this->Session->write('User',$users);
$this->redirect(array('controller'=>'users','action'=>'home'));

}else{
$this->Session->setFlash('Please Check the user details provided');
}
}
}
function home() {
$this->LoginRequired();
$this->set('name',$this->Session->read('User'));

}
function logout() {
$this->Session->delete('User');
$this->Session->setFlash('You have successfully logout');
$this->redirect('/');
}
function register() {
if(!empty($this->data)) {
$user_email['email'] = $this->data['User']['email'];
$check_user = $this->User->find($user_email);//print_r($check_user);
if(empty($check_user['User']['id'])) {
if($this->User->save($this->data)) {
$this->redirect('/');
}else{
$this->set('error',false);
//$this->render();
}
}else{
$this->Session->setFlash('Email Already Exist');
}
}

}
function listusers() {
$users = $this->User->find('all');
$this->set('users',$users);

}
function userdetails($id) {
$this->User->id = $id;
$user = $this->User->read();
print_r($user);
}
function edituser($id) {
$this->User->id = $id;
if(empty($this->data)) {
$this->data = $this->User->read();
}else{
$this->User->save($this->data);
}
//$this->set('user',$user);
}




}
?>

Model
-----------------
array( 'required' => 'true', 'message' =>'Please Enter E-mail address'),
'email' => array(
'Invalid Email format' => VALID_EMAIL,
'Please Enter Email'=>VALID_NOT_EMPTY
),

'password'=>array(
'Enter Password'=>VALID_NOT_EMPTY,
'Password must be at least 4 characters in length' => array(
'rule'=>array('minLength', 4)
)
)



);
}

?>

No comments:

Post a Comment