0

我想从 ACL 插件中的数据库加载资源

我这样做

 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;
    }
}

但这不起作用,因为呈现了白页并且没有打印出来!

4

1 回答 1

1

我发现了问题。问题是在初始化默认适配器之前调用默认数据适配器,诀窍是我必须在引导程序中获取数据适配器并将其传递给插件,所以我这样做

在引导文件中

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

在 Application_Plugin_Acl 中,我这样做

class Application_Plugin_Acl extends Zend_Controller_Plugin_Abstract {

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

这是 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;
      }

}
于 2012-05-22T09:22:27.350 回答