gpt4 book ai didi

zend-framework - Zend 框架 : How to check an additional column while using DbTable Auth Adapter?

转载 作者:行者123 更新时间:2023-12-04 04:32:45 25 4
gpt4 key购买 nike

目前,我收到了一个普通的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com