Thanks in Advance,
When i run bellow Code its showing following error while i add a User.
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'bookstore.users' doesn't exist
I have user Controller in \src\Controller\Admin\UsersController.php
<?php
namespace App\Controller\Admin;
use Cake\Core\Configure;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
use Cake\Event\Event;
class UsersController extends AppController
{
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->loadModel('Admin/Users');
}
public function index()
{
$this->set('headerinfo', array('seoTitle' => 'Dash Board', 'pageTitle' => 'Dashboard', 'breadcrumbs' => null));
$this->set('users', $this->Users->find('all'));
}
public function add()
{
$breadcrumbs = array(
array('', 'Users')
);
$this->set('headerinfo', array('seoTitle' => 'Add User', 'pageTitle' => 'Add User', 'breadcrumbs' => null));
$this->loadModel('Users');
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('User inserted successfully.'));
return $this->redirect(['action' => 'add']);
}
$this->Flash->error(__('Unable to add the user, please contact support'));
}
$this->set('user', $user);
}
}
And Model for Users Table is in following file \src\Model\Table\Admin\UsersTable.php
<?php
namespace App\Model\Table\Admin;
use App\Model\Entity\Admin\User;
use Cake\ORM\Table;
use Cake\ORM\Query;
use Cake\Routing\Router;
use Cake\Validation\Validator;
class UsersTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('admin_users');
$this->primaryKey('auID');
}
}
And Model for User Table's Entity is in following file \src\Model\Entity\Admin\User.php
<?php
namespace App\Model\Entity\Admin;
use Cake\ORM\Entity;
use Cake\Auth\DefaultPasswordHasher;
class User extends Entity {
protected $_accessible = [
'*' => true,
'auID' => false,
];
protected function _setAuPass($password){
return (new DefaultPasswordHasher)->hash($password);
}
}
Table Structure:-
admin_users
Column Type Null Default Comments MIME
auID int(11) No
auName varchar(75) No
auPass varchar(255) No
auFullName varchar(75) No
auStatus varchar(2) Yes A A=Active, I=Inactive
createdOn datetime Yes NULL
modifiedOn datetime Yes NULL
Indexes
Keyname Type Unique Packed Column Cardinality Collation Null Comment
PRIMARY BTREE Yes No auID 1 A No
auName BTREE No No auName 1 A No
auStatus BTREE No No auStatus 1 A Yes