目前,我收到了一个普通的 DbTable Auth Adapter
:
protected function _getAuthAdapter($formData)
{
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('users')
->setIdentityColumn('username')
->setCredentialColumn('password');
$authAdapter->setIdentity($formData['username']);
$authAdapter->setCredential(md5($formData['password']));
return $authAdapter;
}
但我想检查数据库中的附加列(例如
IsActive
)。我不知道这是否可以通过适配器完成。如何才能做到这一点?
最佳答案
我也有类似的情况,我扩展了Zend_Auth_Adapter_DbTable
满足我的需求:
class My_Auth_Adapter_DbTable extends Zend_Auth_Adapter_DbTable
{
protected $_customerIdColumn = 'customer_id';
protected $_customerId = false;
public function setCustomerId($id) {
$this->_customerId = $id;
return $this;
}
public function getCustomerId() {
return ($this->_customerId !== false) ? $this->_customerId : '';
}
public function _authenticateCreateSelect() {
$dbSelect = parent::_authenticateCreateSelect();
$dbSelect->where($this->_zendDb->quoteIdentifier($this->_customerIdColumn, true) . ' = ?',
$this->getCustomerId());
return $dbSelect;
}
}
然后我像这样使用它:
public function getAuthAdapter(array $params)
{
$authAdapter = new My_Auth_Adapter_DbTable(
$params['db_adapter'],
'users',
'username',
'password',
'? AND active = 1'
);
$authAdapter->setIdentity($params['username'])
->setCustomerId($params['customer_id'])
->setCredential($params['password']);
return $authAdapter;
}
关于zend-framework - Zend 框架 : How to check an additional column while using DbTable Auth Adapter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1871142/