Search code examples
zend-frameworkzend-authzend-acl

Zend_ACL how to get role?


after reading the Zend documentation and some posts here I could not figure out how to get my user role out of a user table.

At the moment I use Zend_Auth like this in an AuthController:

// Set authentication adapter and map ID and Cre.
// only admins could log in here
$adapter = new Zend_Auth_Adapter_DbTable($this->db,
            'customers',
            'login',
            'password',
            'MD5(?)');
$adapter->setIdentity($form->getValue('username'))
    ->setCredential($form->getValue('password'));

// Check if authentification is right
$result = Zend_Auth::getInstance()->authenticate($adapter);

if (!$result->isValid()) {
    ..
}

And later check it via an Zend_Controller_Plugin and route depending on the result:

if (Zend_Auth::getInstance()->hasIdentity()) {
        return;
} elseif ($request->getControllerName() == 'auth' || $request->getControllerName() == 'index') {
        return;
} else {
        $request->setControllerName('index');
        $request->setActionName('index');
        return;
}

Now I want to change the route depending on the roll of the user. If the user is an administrator he can reach the AdminController, but how do I get the role out of my user table? The column is called type and it contains a string witch indicates the role.

I hope you can help me.

Greetings,

-lony


Solution

  • Store your auth result row in Zend_Auth using the adapter's getResultRowObject method. See http://framework.zend.com/manual/en/zend.auth.adapter.dbtable.html#zend.auth.adapter.dbtable.advanced.storing_result_row