userscontroller.php
public function login(){
if($this->request->is(‘post’)){
echo “
”;print_r($this->request->is(‘post’)); die;
$user = $this->Auth->identify();
//echo “”;print_r($user); die;
if($user){
$this->Auth->setUser($user);
$this->Flash->success((‘Login successful.’));
return $this->redirect([‘Controller’=>‘Users’, ‘action’=>‘index’]);
}
$this->Flash->error((‘user could not login.try again.’));
}
}login.ctp
Appcontroller.php public function initialize() { parent::initialize();Login
<?= $this->form->create(); ?> <?= $this->Form->control('email'); ?> <?= $this->Form->control('password', array('type'=> 'password')); ?> <?= $this->Form->submit('Login',array('class'=>'button')); ?> <?= $this->form->end(); ?>$this->loadComponent('RequestHandler', [ 'enableBeforeRedirect' => false, ]); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'fields' => [ 'username' => 'email', 'password' => 'password' ] ] ], 'loginAction' => [ 'controller' => 'Users', 'action' => 'login' ] ]);