SQLSTATE[42S22]:未找到列:1054未知列';Employee.username';在';其中第'条;

SQLSTATE[42S22]:未找到列:1054未知列';Employee.username';在';其中第'条;,sql,cakephp,authentication,login,controller,Sql,Cakephp,Authentication,Login,Controller,我试图让我的登录使用CakePHP2.4.7,但我似乎遇到了问题。我使用“员工”作为数据库的用户 我犯了这个错误 SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“Employee.username” 在我将所有“用户名”字段更改为employee_用户名后,仍然会出现相同的错误。有人能帮忙吗 以下是我的AppController、EmployeeController、Employee和login.ctp代码: AppController: class AppCon

我试图让我的登录使用CakePHP2.4.7,但我似乎遇到了问题。我使用“员工”作为数据库的用户

我犯了这个错误

SQLSTATE[42S22]:未找到列:“where子句”中的1054未知列“Employee.username”

在我将所有“用户名”字段更改为employee_用户名后,仍然会出现相同的错误。有人能帮忙吗

以下是我的AppController、EmployeeController、Employee和login.ctp代码:

AppController:

class AppController extends Controller {

    public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'employees', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'employees', 'action' => 'login'),
        'authError' => 'You must be logged in to view this page.',
        'loginError' => 'Invalid Username or Password entered, please try again.',
        'authenticate' => array(
            'Form' => array(
            'fields' => array('username' => 'employee_username', 'password' => 'employee_pw'),
            'userModel'=>'Employee'
            ))

    ));

// only allow the login controllers only
public function beforeFilter() {
    $this->Auth->allow('login');
}
}
class EmployeesController extends AppController {

/**
 * Components
 *
 * @var array
 */
    //public $components = array('Paginator');
    public $paginate = array(
        'limit' => 25,
        'conditions' => array('status' => '1'),
        'order' => array('Employee.employee_username' => 'asc' ) 
    );

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('login','add'); 

    }



    public function login() {

        //if already logged-in, redirect
        if($this->Session->check('Auth.Employee')){
            $this->redirect(array('action' => 'index'));      
        }

        // if we get the post information, try to authenticate
        if ($this->request->is('post')) {

            $result = $this->Employee->findByUsername($this->data['Employee']['employee_username']);
            if ($this->Auth->login(/*$result['Employee']*/)) {
                $this->Session->setFlash(__('Welcome, '. $this->Auth->user('employee_username')));
                $this->redirect($this->Auth->redirectUrl());
            } else {
                $this->Session->setFlash(__('Invalid username or password'));
            }
        } 
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

/**
 * index method
 *
 * @return void
 */
    public function index() {
        $this->paginate = array(
            'limit' => 6,
            'order' => array('Employee.employee_username' => 'asc' )
        );
        $employees = $this->paginate('Employee');
        $this->set(compact('employees'));
    }
员工控制员:

class AppController extends Controller {

    public $components = array(
    'DebugKit.Toolbar',
    'Session',
    'Auth' => array(
        'loginRedirect' => array('controller' => 'employees', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'employees', 'action' => 'login'),
        'authError' => 'You must be logged in to view this page.',
        'loginError' => 'Invalid Username or Password entered, please try again.',
        'authenticate' => array(
            'Form' => array(
            'fields' => array('username' => 'employee_username', 'password' => 'employee_pw'),
            'userModel'=>'Employee'
            ))

    ));

// only allow the login controllers only
public function beforeFilter() {
    $this->Auth->allow('login');
}
}
class EmployeesController extends AppController {

/**
 * Components
 *
 * @var array
 */
    //public $components = array('Paginator');
    public $paginate = array(
        'limit' => 25,
        'conditions' => array('status' => '1'),
        'order' => array('Employee.employee_username' => 'asc' ) 
    );

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('login','add'); 

    }



    public function login() {

        //if already logged-in, redirect
        if($this->Session->check('Auth.Employee')){
            $this->redirect(array('action' => 'index'));      
        }

        // if we get the post information, try to authenticate
        if ($this->request->is('post')) {

            $result = $this->Employee->findByUsername($this->data['Employee']['employee_username']);
            if ($this->Auth->login(/*$result['Employee']*/)) {
                $this->Session->setFlash(__('Welcome, '. $this->Auth->user('employee_username')));
                $this->redirect($this->Auth->redirectUrl());
            } else {
                $this->Session->setFlash(__('Invalid username or password'));
            }
        } 
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

/**
 * index method
 *
 * @return void
 */
    public function index() {
        $this->paginate = array(
            'limit' => 6,
            'order' => array('Employee.employee_username' => 'asc' )
        );
        $employees = $this->paginate('Employee');
        $this->set(compact('employees'));
    }
员工模式:

public $validate = array(
        'id' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'employee_name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'date_hired' => array(
            'date' => array(
                'rule' => array('date'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        /*'employee_phone_number' => array(
            'phone' => array(
                'rule' => array('phone'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),*/
        'employee_email' => array(
            'email' => array(
                'rule' => array('email'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'employee_dob' => array(
            'date' => array(
                'rule' => array('date'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'access_level' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'employee_username' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'employee_pw' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );
login.ctp

<div class=“employees form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('Employee'); ?>
    <fieldset>
        <legend>
            <?php echo __('Please enter your username and password'); ?>
        </legend>
        <?php echo $this->Form->input('employee_username');
        echo $this->Form->input('password');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>

如何处理与错误消息相关的内容,例如表名和列名?为什么不按照文档中的说明使用login()?您的自定义代码非常非常规,可能会在某个时候出现问题。您以前问过类似的问题,您的问题是关于
您在AuthComponent方面的经验很少。。根据用户模型进行大量练习,然后您可以尝试使用不同的模型。。嗯,如果你想解决你目前的问题,那么我们必须问你很多问题,这会使你的问题变得混乱。。