palAlaa
palAlaa

Reputation: 9838

Access database from ACL plugin

I want to load resources from database inside the ACL plugin

I make like this

 class My_ACL extends Zend_Acl {

protected $_role_id;
protected $_userResource;

public function __construct() {

    try {
        $db = Zend_Db_Table::getDefaultAdapter();
        $stmt = $db->query("CALL getUserPrivileges(?)", 998877445);

        //Returns an array containing all of the result set rows  
        $rows = $stmt->fetchAll();

        $stmt->closeCursor();
        print_r($rows);

        return $rows;
    } catch (Exception $e) {
        echo 'error ' . $e;
    }
}

but this doesn't work since white page is rendered and nothing is print out!

Upvotes: 0

Views: 600

Answers (1)

palAlaa
palAlaa

Reputation: 9838

I found the problem. The problem was calling default data adapter before initializing the default adapter, the trick was I have to get the data adapter inside the bootstrap and pass it to the plugin, so I make like this

in bootstrap file

protected function _initPlugins() {
    $this->bootstrap('db');
    $db = $this->getResource('db');
    $front = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new Application_Plugin_Acl($db));
}

and in the Application_Plugin_Acl, I make like this

class Application_Plugin_Acl extends Zend_Controller_Plugin_Abstract {

 public function __construct($db) {
    $this->_acl = new My_ACL($db);
}
}

and here's my_ACL

 class My_ACL extends Zend_Acl {


public function __construct($db) {

     try {

      $stmt = $db->query("CALL getUserPrivileges(?)", 998877445);

      //Returns an array containing all of the result set rows
      $rows = $stmt->fetchAll();

      $stmt->closeCursor();
      print_r($rows);

      return $rows;
      } catch (Exception $e) {
      echo 'error ' . $e;
      }

}

Upvotes: 1

Related Questions