Yii-debug-toolbar extension

    Good time of the day to the Khabravchians.

    Today I would like to talk about one wonderful extension of yii-debug-toolbar from Sergey Malyshev.

    Briefly


    This extension adds a very nice and comfortable debug panel.

    yii-debug-toolbar has 5 tabs:
    • Server: displays information from phpinfo ();
    • Time: displays page load time, memory usage and session size;
    • Globals: displays dumps of global variables ($ _SERVER, $ _COOKIE, $ _SESSION, $ _POST, $ _GET, $ _FILES);
    • Settings: displays the application config (all parameters, components and global settings);
    • SQL: displays information about the SQL server and the log for SQL queries (the query itself and execution time);
    • Logging: displays the log information (sent via Yii :: log).




    Installation


    So, to install such a panel on your test server, you need to download the source of the latest version from here www.yiiframework.com/extension/yii-debug-toolbar . Unpack the archive into the / protected / extensions folder. Then in the config register in the log component
    #...
    'log'=>array(
    	'class'=>'CLogRouter',
    	'enabled'=>YII_DEBUG,
    	'routes'=>array(
    		#...
    		array(
    			'class'=>'CFileLogRoute',
    			'levels'=>'error, warning',
    		),
    		array(
    			'class'=>'application.extensions.yii-debug-toolbar.YiiDebugToolbarRoute',
    			'ipFilters'=>array('127.0.0.1','192.168.1.215'),
    		),
    	),
    ),
    #...
    

    After which, a blue beetle (ala firebug) should appear at the top right. If you have one, then you did everything right.

    Customization


    The component inherits all parameters from the CLogRouter. But he has one parameter of his own: ipFilters. This is an array of allowed IP addresses. If you do not want to accidentally upload a copy of the debug bar to the production, then enter your IP address there, and the panel will be available only from your computer.
    Parameters inherited from CLogRouter:
    • bool enabled: if false, then the debug is disabled (I usually put the constant YII_DEBUG there, then you can quickly and globally disable debug);
    • string levels: a list of logging levels separated by commas or spaces;
    • string categories: a list of logging categories, separated by commas or spaces;
    • array filter: additional filters (e.g. CLogFilter);
    • array logs: logs collected during program execution.

    For the sweet. How to create your own panel in yii-debug-toolbar?


    The author of the extension took care of the developers using his product and made it possible to safely add his own tabs. Let's try to create a panel called "Test". To do this, add a new YiiDebugToolbarPanelTest.php file to the / protected / extensions / yii-debug-toolbar / panels folder and create a new YiiDebugToolbarPanelTest class in it, which inherits from YiiDebugToolbarPanel. This class should implement 5 methods:
    • getMenuTitle: the method returns the name of the tab in the sidebar;
    • getMenuSubTitle: the method returns the description of the tab in the sidebar;
    • getTitle: the method returns the name of the tab directly inside the tab (above, on the yellow bar);
    • getSubTitle: the method returns the description of the tab directly inside the tab (above, on the yellow bar);
    • run: displays the content of the tab.

    And add a tab to the $ _panels property of the YiiDebugToolbar class (/protected/extensions/yii-debug-toolbar/YiiDebugToolbar.php)
    class YiiDebugToolbarPanelTest extends YiiDebugToolbarPanel{
        function getMenuTitle(){ return 'Test'; }
        function getMenuSubTitle(){ return 'subtest'; }
        function getTitle(){ return 'TEST v1.0'; }
        function getSubTitle(){ return 'Hello Vasya'; }
    	function run(){
    		echo '

    '.self::getSubTitle().'

    '; echo rand(); } }

    Result: If anyone is interested, in the next article I can tell you how to write your own logger. With respect, Roman.





    Also popular now: