LoginControlller.php
namespace App\Controller;
use Cake\ORM\TableRegistry;
use App\Controller\AppController;
class LoginController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash'); // Include the FlashComponent
}
public function index()
{
$this->set('login', $this->Login->find('all'));
$this->set(compact('login'));
}
public function add()
{
$login = $this->Login->newEntity();
if ($this->request->is('post')) {
$login = $this->Login->patchEntity($login, $this->request->getData());
if ($this->Login->save($login)) {
$this->Flash->success(__('Your login has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('Unable to add your login.'));
}
$this->set('login', $login);
}
}
add.ctp
Add User
<?php
echo $this->Form->create($login);
echo $this->Form->control('username');
echo $this->Form->control('password');
echo $this->Form->button(__('Save Article'));
echo $this->Form->end();
?>
Model/Login.php
<?php namespace App\Model\Table; App::uses('AuthComponent', 'Controller/Component'); use Cake\ORM\Table; use Cake\Validation\Validator; class Login extends AppModel { public $validate = array('username' => array('rule' => 'notEmpty')); } ?>validation added in Login.php is not working.Please help