在zend框架2中启用BjyProfiler模块

时间:2014-06-04 07:26:03

标签: php zend-framework2

我刚刚在我的应用程序中安装了zend开发人员工具模块和BjyProfiler模块。 Zend开发人员工具工作正常,zend开发人员工具模块和BjyProfiler模块显示在工具栏的模块列表中。但是BjyProfiler工作不正常,当我点击zend开发人员工具栏的数据库按钮时,它显示如下: enabling bjyprofiler

我在github中浏览了BjyProfiler自述文件。阅读自述文件后,我不知道在何处放置此代码以启用BjyProfiler进行查询调试。

$profiler = $sl->get('Zend\Db\Adapter\Adapter')->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();

总之,我的问题是如何放置此代码以及如何成功启用BjyProfiler来调试查询错误。谢谢你的关注。

1 个答案:

答案 0 :(得分:0)

添加到aplication.config.php:

'modules' => array(
    //...
    'BjyProfiler',
    'ZendDeveloperTools',
    'MyOtherModule',
    //...
),

在config / autoload&中创建bjyprofiler.local.php。添加:

$dbParams = array(
    'database'  => 'ZF2sample',
    'username'  => 'root',
    'password'  => '123456',
    'hostname'  => 'localhost',
    // buffer_results - only for mysqli buffered queries, skip for others
    'options' => array('buffer_results' => true)
);

return array(
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => function ($sm) use ($dbParams) {
                $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter(array(
                    'driver'    => 'pdo',
                    'dsn'       => 'mysql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'],
                    'database'  => $dbParams['database'],
                    'username'  => $dbParams['username'],
                    'password'  => $dbParams['password'],
                    'hostname'  => $dbParams['hostname'],
                ));

                if (php_sapi_name() == 'cli') {
                    $logger = new Zend\Log\Logger();
                    // write queries profiling info to stdout in CLI mode
                    $writer = new Zend\Log\Writer\Stream('php://output');
                    $logger->addWriter($writer, Zend\Log\Logger::DEBUG);
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\LoggingProfiler($logger));
                } else {
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
                }
                if (isset($dbParams['options']) && is_array($dbParams['options'])) {
                    $options = $dbParams['options'];
                } else {
                    $options = array();
                }
                $adapter->injectProfilingStatementPrototype($options);
                return $adapter;
            },
        ),
    ),
);

浏览器中的F5!