Zend Framework 2 : ZendDeveloperTools : The ZF2 tools You must install
ZendDeveloperTools is a Module for developer and debug tools for working with the ZF2 MVC layer. It can show you a request method, response code, current controller/action, current route we access, execution time, memory consumption, grab the profiler of Zend\Db adapter instance, and Zend Framework version you currently use.
The success installed :
ZendDeveloperTools Module installation :
1. Clone ZendDeveloperTools from Github
git clone git://github.com/zendframework/ZendDeveloperTools.git
2. Copy to vendor folder
3. Copy `ZendDeveloperTools/config/zenddevelopertools.local.php.dist` to
`./config/autoload/zenddevelopertools.local.php`. Change the settings
if you like to.
4. Add the following in your `index.php` first line :
define('REQUEST_MICROTIME', microtime(true));
5. Enable it in application.config.php
<?php return array( 'modules' => array( 'Application', 'ZendDeveloperTools', ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), );
If you wish to profile Zend\Db, you have to install and enable [BjyProfiler] :
1. Clone BjyProfiler Module from Github/
git clone git://github.com/bjyoungblood/BjyProfiler.git
2. Copy to vendor folder
3. Change your database configuration like the following :
$dbParams = array( 'database' => 'zf2', 'username' => 'developer', 'password' => '123456', 'hostname' => 'localhost' ); 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' => 'pgsql:dbname='.$dbParams['database'].';host='.$dbParams['hostname'], 'database' => $dbParams['database'], 'username' => $dbParams['username'], 'password' => $dbParams['password'], 'hostname' => $dbParams['hostname'], )); $adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler); $adapter->injectProfilingStatementPrototype(); return $adapter; }, ), ), );
4. Enable it in application.config.php
<?php return array( 'modules' => array( 'Application', 'ZendDeveloperTools', 'BjyProfiler' ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), );
If your installation succeded, you can debug your application :
$profiler = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter')->getProfiler(); $queryProfiles = $profiler->getQueryProfiles(); foreach($queryProfiles as $key=>$row) { print_r($row->toArray()); }
And the result will like this :
References :
1. https://github.com/zendframework/ZendDeveloperTools/blob/master/README.md
2. https://github.com/bjyoungblood/BjyProfiler/blob/master/README.md
[…] https://samsonasik.wordpress.com/2012/08/07/zend-developer-tools-zf2-debug-toolbar-install/ […]
Note that profiling through Zend Developer Tools is also available for Doctrine with DoctrineORMModule (the official ZF 2 Doctrine module ;-).
thanks 😉
How can achieve this with zend 2 for doctrine2?
install DoctrineORMModule : https://github.com/doctrine/DoctrineORMModule
I installed already, but i don’t know how to show profiler informations in zend 2
configure your composer.json :
and run,
Follow https://github.com/doctrine/DoctrineORMModule/blob/master/README.md configuration.
Last but not least, register at application.config.php
Tank you Malik for take time to responde me but how i said i already install doctrine module, installed on: vendor/doctrine/doctrine-orm-module. I google it more and i find what to do, I write here maybe would help someone else who just started with zend 2. So all i have to do is put in root config autoload this:
return array(
‘zenddevelopertools’ => array(
‘profiler’ => array(
‘enabled’ => true,
‘strict’ => true,
‘verbose’ => true,
‘flush_early’ => false,
‘cache_dir’ => ‘data/cache’,
‘collectors’ => array(),
‘verbose_listeners’ => array(‘application’ => array(
‘ZDT_TimeCollectorListener’ => true,
‘ZDT_MemoryCollectorListener’ => true,
))
),
‘toolbar’ => array(
‘enabled’ => true,
‘auto_hide’ => false,
‘position’ => ‘bottom’,
‘version_check’ => false,
‘entries’ => array(),
),
),
);
it just like number 3 step in my blog post 🙂
q udah ikutin langkah2 nya tapi ga jalan, trus q coba copy ZendDeveloperTools ke folder module baru jalan gan. kok bisa ya
berarti di application.config.php kamu cuma ada folder module, tambahkan jg folder vendor. kalau ga jalan, update zf2 terbaru.
gan langkah 3. Change your database configuration like the following : itu file apa yg diedit? aq pake doctrine
Ikuti petunjuk yg ada di sini https://github.com/doctrine/DoctrineORMModule/blob/master/README.md
Hi!
You can move all DB config parameters to /config/autoload/local.php:
return array(
‘db’ => array(
‘username’ => ‘user1234’,
‘password’ => ‘passABCD’,
‘driver’ => ‘Pdo’,
‘dsn’ => ‘mysql:dbname=db_name;host=localhost’,
‘driver_options’ => array(
PDO::MYSQL_ATTR_INIT_COMMAND => ‘SET NAMES \’UTF8\”
),
),
);
In global.php we can leave only insensitive data (db name, password, login, etc):
[…]
‘Zend\Db\Adapter\Adapter’ => function ($sm) {
$config = $sm->get(“config”);
$adapter = new BjyProfiler\Db\Adapter\ProfilingAdapter($config[‘db’]);
$adapter->setProfiler(new BjyProfiler\Db\Profiler\Profiler);
$adapter->injectProfilingStatementPrototype();
return $adapter;
},
[…]
Now configuration file is more friendly. 😉
Best regards!
Piotr
great! thanks.
Very cool! Thanks!
Denis Ryabov has posted a nice solution to view queries inside the toolbar template:
http://stackoverflow.com/questions/13275569/how-to-view-db-queries-generated-by-tablegateway-in-zend-framework-2
It would be nice to see this feature inside the BjyProfiler container.
great ! you can contribute to https://github.com/bjyoungblood/BjyProfiler 😉
[…] Zend Developer Tools GIT tutorial […]
hi i have install zenddevelopertools modules with bjyoungblood/BjyProfiler module but still showing
https://a248.e.akamai.net/camo.github.com/94e40145f871bc995499a793a19dc7a82950747c/687474703a2f2f692e696d6775722e636f6d2f414f6a65422e706e67
i have configure all thing according to zenddevelopertools guide and you say in this post but still get above image result
Please help me ..
Thanks
check BjyProfiler guide too, and don’t forget to add to the config/application.config.php
i did this but no effect , my config/application.config.php content is
array(
‘ZendDeveloperTools’,
‘DoctrineModule’,
‘DoctrineORMModule’,
‘BjyProfiler’,
‘Application’,
‘Blog’,
‘Incuser’,
// ‘Myacl’,
//’ZfcBase’,
//’ZfcUser’
),
‘module_listener_options’ => array(
‘config_glob_paths’ => array(
‘config/autoload/{,*.}{global,local}.php’,
),
‘module_paths’ => array(
‘./module’,
‘./vendor’,
),
),
);
Same Problem….
I Want to write my own sql script in my controller in my index action..tell how to write the query and how to fetch the data in index phtml file
don’t write query in controller, write on model. read the docs http://zf2.readthedocs.org
Can you write a tutorial about mongodb and zend framework 2 plz, I always got error AnnominationsRegistertry not found in DoctrineModule/Module . Thank you.
Simply install the ZF2 module for this purpose:
https://github.com/doctrine/DoctrineMongoODMModule
It should also automatically integrate into the toolbar.
Abdul, thank you for all your usefull posts!
I have a question about the meaning of the drawer icon. Does it represent de total load of the page?
When I load my page de developer-tool-bar it says 7.75 Mb (= 992 KB) but if I check my firefox console it says 321.73 KB.
How should I understand it? Thank you
I think firefox console only check memory to load asset (html/js/css), and the zenddevelopertools check memory to consume asset , php & database execution 🙂
BjyProfiler multiple Db help me ….
I have no idea. maybe you need to create new issue in bjyprofiler repository : https://github.com/bjyoungblood/BjyProfiler/issues
where to put this code
$profiler = $this->getServiceLocator()->get(‘Zend\Db\Adapter\Adapter’)->getProfiler();
$queryProfiles = $profiler->getQueryProfiles();
foreach($queryProfiles as $key=>$row)
{
print_r($row->toArray());
}
I am not clear. Please help me
I have the same problem !
thanks Samsonasik for the tuto i’ve followed the tuto but i’ve get a problem , i have an application working with zend franmework 2 and doctrine.when i added zendDevelopperTools i can’t log in , the application stoped working.
problem fixed , just edit the zenddevelopertools.local.php just like mentionned here :
http://stackoverflow.com/questions/11519800/zenddevelopertools-module-not-displaying-a-toolbar-in-zf2-beta5
[…] 参考サイト https://samsonasik.wordpress.com/2012/08/07/zend-developer-tools-zf2-debug-toolbar-install/ […]
Thanks for your post
Can you please tell me how i remove it when going to online
set application environments, for ex: ‘development’, ‘production’, ‘test’, etc. so, when you change the environment you can enable/disable modules you need.
At first try I’ve downloaded it from github by: git clone
and get error:
Fatal error: Uncaught exception ‘Zend\ModuleManager\Exception\RuntimeException’ with message ‘Module (ZendDeveloperTools) could not be initialized.’
At second try I’ve used composer:
composer require zendframework/zend-developer-tools:dev-master
and it works like a charm 🙂
current ZendDeveloperTools now rely on composer for autoloading, that’s why it works with composer.
Please give some examples for Zend2+MongoDB+Doctrine2
I don’t have example, but you may try https://github.com/doctrine/DoctrineMongoODMModule
That’s a useful tool. It helps me.
Thanks a lot.
How would you configure for multiple database?
if i remember correctly, BjyProfiler only show ‘Zend\Db\Adapter\Adapter’ service in the ZendDeveloperTools.
so than you can’t profile multiple databases? seem rather short sighted. Is there a way to do this?
Well, I never try it before.
You may probably need to create multiple adapters ( https://samsonasik.wordpress.com/2013/07/27/zend-framework-2-multiple-named-db-adapter-instances-using-adapters-subkey/ ) , write service delegator to apply:
for each key of db, and then do effort to make it shown in the toolbar, or contribute to its repository https://github.com/bjyoungblood/BjyProfiler .
It is open source.