Scripts
Zend Auth - Multiple identity columns
Onlangs bouwde ik een applicatie waarin ik meerdere ‘identity colums’ had. (Customer, Username) Aangezien Zend_Auth dat standaard niet ondersteund was ik genoodzaakt een eigen Auth adapter te schrijven. Als je dit script wilt gebruiken moet je wel wat van Zend(_Auth) afweten. Ik ga hier verder niet op in, dit is gewoon een snippet voor mensen die hem nodig hebben. Veel succes, en wanneer je vragen hebt, hoor ik dat graag! Niels kieviet
zend_auth.php
<?php
class MyAuth_Adapter extends Zend_Auth_Adapter_DbTable
{
protected $customerColom = 'customer_id';
protected $customer;
public function __construct($dbAdapter)
{
parent::__construct($dbAdapter);
}
public function setCustomer($customer)
{
if (is_null($customer) || !is_string($customer)) {
throw new Adapter_Auth_Exception('Parameter ' .$customer. ' is leeg of is geen string');
}
$this->customer = $customer;
return $this;
}
public function getCustomerId()
{
$tableCustomer = new Table_Customer();
return $tableCustomer->getCustomerByName($this->customer); // of iets in die zin.
}
protected function _authenticateCreateSelect()
{
$select = parent::_authenticateCreateSelect();
$select->where(
$this->_zendDb->quoteIdentifier(
$this->customerColom, true
). '= ?', $this->getCustomerId()
);
return $select;
}
}
Reacties
0