यह login.ctp फाइल है
<h1>login page </h1>
<?php
echo $this->Form->create('User');
echo $this->Form->input('name');
echo $this->Form->input('password');
echo $this->Form->end('login');
?>
हम इसको user के view फाइल मै save करे गे
फिर उसके बाद controller मै कोड लिखे गे
We save this to user's file.
After that the code will be written to the controller
public function login(){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash('Please check your email or password');
}
}
}
वही पे logout का भी कोड लिखे गे
The same payout will also be written code
public function logout(){
$this->Auth->logout();
$this->redirect('login');
}
login का मतलब कोई भी password नहीं देखना चाहिए उसके लिए हम
Controller का Add में हम ये लिखे गे
Login does not mean any password should be seen for us
In the Controller's Add, we will write this
public function add() {
if ($this->request->is('post')) {
$this->User->create();
$this->request->data['User']['password'] = AuthComponent::password($this->request->data['User']['password']);
$this->request->data['User']['role'] = 1;
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}
ये कोड बस add करना है
Just add this code
उसके बाद appController
class AppController extends Controller {
public $components = array('Session','Auth');
}
में ये लिखना है
No comments:
Post a Comment