Zend Auth有两个标识列

Son*_*nny 1 php zend-framework zend-auth

Zend_Auth用来验证用户凭据并遇到问题.我需要一个双列标识.这两列是用户名和客户标识符.在identityColumn设置和setIdentity()方法不允许这种情况.我试图通过使用该credentialTreatment设置来实现此目的,但是当我为两个或更多客户提供重复的用户名时,它仅为zend_auth_credential_match其他客户计算为false,而不是将这些用户过滤掉.

这是Zend Auth执行的结果查询的清理示例:

SELECT `users`.*,
    (CASE
        WHEN `password` = 'password'
            AND active = 1
            AND customer_id = 1
            THEN 1 
        ELSE 0
        END) AS `zend_auth_credential_match`
FROM `users`
WHERE (`username` = 'username')
Run Code Online (Sandbox Code Playgroud)

是否有必要扩展Zend_Auth模块来执行此操作?有没有其他人做过它可以提供一个例子?

谢谢!

gna*_*arf 5

我想你需要编写自己的子类Zend_Auth_Adapter_DbTable来处理这个问题.

就像是:

class My_Auth_Adapter extends Zend_Auth_Adapter_DbTable {
  protected $_customerColumn = '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() {
    $select = parent::_authenticateCreateSelect();
    $select->where($this->_zendDb->quoteIdentifier($this->_customerColumn, true)." = ?", $this->getCustomerId());
    return $select;
  }
}
Run Code Online (Sandbox Code Playgroud)