【问题标题】:Zend Framework with ZFDebug, how to get the db adapterZend Framework 与 ZFDebug,如何获取 db 适配器
【发布时间】:2011-08-12 20:35:02
【问题描述】:

我的 application.ini 文件中有以下内容

resources.db.adapter = "PDO_MYSQL" resources.db.params.host = "localhost" resources.db.params.username = ".." resources.db.params.password = ".." resources.db.params.dbname = "lsc3_base" resources.db.isDefaultTableAdapter = true

现在完美运行,我可以查询数据库没有问题。

我正在尝试安装 ZFDebug,在我的主 bootstrap.php 文件中使用以下内容也很容易

` 受保护函数 _initZFDebug() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace('ZFDebug');

    $options = array(
        'plugins' => array('Variables', 
            'Time',
            #'Auth',
            'Memory',
            'Registry', 
            'Database' => array('adapter' => $db), 
            'File' => array('basePath' => '/path/to/project'),
            #'Cache' => array('backend' => $cache->getBackend()), 
            'Exception')
    );
    $debug = new ZFDebug_Controller_Plugin_Debug($options);

    $this->bootstrap('frontController');
    $frontController = $this->getResource('frontController');
    $frontController->registerPlugin($debug);
} 

` 现在这显然给了我一个通知,说 $db undefined。

问题是我如何获得$db?

我尝试了以下方法: $db = Zend_Db_Table::getDefaultAdapter(); $db = $this->getPluginResource('db');

我假设它不起作用,因为它在完成我的引导程序中的所有事情之后连接到数据库。我该如何解决这个问题?

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    这应该会有所帮助,像这样创建一个 $db 变量:

    $this->bootstrap('db');
    $db = $this->getPluginResource('db')->getDbAdapter();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      相关资源
      最近更新 更多