3

Can someone give me some instructions on how to get the user roles into my zf2-toolbar.

I have problems getting the user-roles from my role-entity visible in my zend-developer-toolbar. Normaly I solve my own problems, but in this case I'm out of ideas. I'm using ZfcUser, BjyAuthorize and Doctrine2. I cannot find any instructions on how to make the user-roles show up on the toolbar. I used composer to install all dependencies. My composer file looks like this:

"require": {
    "php": ">=5.3.3",
    "zendframework/zendframework": "2.*",
    "doctrine/common": ">=2.3-dev,<2.5-dev",
    "zf-commons/zfc-user": "0.*",
    "bjyoungblood/bjy-authorize": "1.2.*",
    "doctrine/doctrine-orm-module": "0.*",
    "zendframework/zftool": "dev-master",
    "zendframework/zend-developer-tools": "dev-master",
    "zf-commons/zfc-user-doctrine-orm": "dev-master",
    "bjyoungblood/bjy-profiler": "dev-master"
}

In the toolbar I also still get the message:

Error
You have to install or enable @bjyoungblood's Zend\Db Profiler to use this feature.

While in my config/autoload/module.zenddevelopertools.local.php I did set the profiler to enabled and it is also installed, at least I checked that with my composer.phar if.

'profiler' => array(
    'enabled' => true,

    ...
),

Would be great if someone can help me out, Thx!

Wilt
  • 41,477
  • 12
  • 152
  • 203
  • 1
    in your **application.config.php** have you activated **BjyProfiler** ? – Remi Thomas Apr 20 '13 at 19:26
  • 1
    BjyProfiler has nothing to do with the UserRoles being displayed. The important thing is to load the ZendDeveloperToolbar before BjyAuthorize. There should be not a single configuration needed to have the Role shown in your toolbar - everything the most current version? – Sam Apr 20 '13 at 21:47
  • 1
    i am still facing above problem also BjyProfiler is not working while i have already install and enable this module. please Help me – Bineet Chaubey Jun 04 '13 at 09:07
  • 2
    I am also getting same problem, did you solve it @Wilt? – regeint Aug 20 '13 at 08:13
  • Nope not yet solved. I never got useful responses. I stopped using BjyAuthorize so it is not probable I will come with something soon. If I always post my solutions on StackOverflow so if I find something you can read it here later. If you find out something useful please post it here! – Wilt Nov 13 '13 at 10:07
  • @regeint I had the same problem getting BjyProfiler to show up in the toolbar and just added an answer that it working for me. – drew010 Nov 14 '13 at 07:24

1 Answers1

3

I found this thread by searching for the error message You have to install or enable @bjyoungblood's Zend\Db Profiler to use this feature because when I first installed ByjProfiler I could not get it to show query statistics in the developer toolbar.

The readme file and documentation had slightly different code for activating the profiler in the toolbar but after some playing around I got it working.

In config/autoload/global.php, I had the following already set:

return array(
    // ...
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
);

To get ByjProfiler working in ZDT toolbar, I changed it to:

return array(
    //...
    'service_manager' => array(
        'factories' => array(
            //'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
            'Zend\Db\Adapter\Adapter' => function($sm) {
                $config = $sm->get('Configuration');
                $modules = $sm->get('ModuleManager')->getLoadedModules();

                if (isset($modules['BjyProfiler'])) { // module is enabled in application.config.php
                    $adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter($config['db']);
                    $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler());
                    if (isset($config['db']['options']) && is_array($config['db']['options'])) {
                        $options = $config['db']['options'];
                    } else {
                        $options = array();
                    }
                    $adapter->injectProfilingStatementPrototype($options);
                } else {
                    $adapter = new Zend\Db\Adapter\Adapter($config['db']);
                }

                return $adapter;
            }
        ),
    ),
);

I derived most of that code from byj-profiler/config/module.config.php but changed it to check the loaded modules for BjyProfiler being active. If it is not, it falls back to the regular Zend\Db\Adapter\Adapter, otherwise tries to configure BjyProfiler using your DB settings from the application config.

Hope that helps!


EDIT:

To elaborate further, it appears the issue getting BjyProfiler to work by default had to do with using the AdapterServiceFactory for Zend\Db\Adapter\Adapter.

If I have BjyProfiler enabled, but delete the DB factories from the service manager, the profiler works automatically without additional code or config, but if I remove BjyProfiler from application.config.php, then my DB connection is broken.

If I have the AdapterServiceFactory string in the service manager and BjyProfiler enabled, it seems to override using BjyProfiler as the DB adapter and therefore don't get the profiler working in the toolbar.

drew010
  • 68,777
  • 11
  • 134
  • 162