Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
# CakePHP DebugKit [![Build Status](https://secure.travis-ci.org/cakephp/debug_kit.png?branch=master)](http://travis-ci.org/cakephp/debug_kit)
2
 
3
DebugKit provides a debugging toolbar and enhanced debugging tools for CakePHP applications.
4
 
5
## Requirements
6
 
7
The master branch has the following requirements:
8
 
9
* CakePHP 2.2.0 or greater.
10
* PHP 5.3.0 or greater.
11
 
12
## Installation
13
 
14
* Clone/Copy the files in this directory into `app/Plugin/DebugKit`
15
 
16
This can be done with the git submodule command
17
```sh
18
git submodule add https://github.com/cakephp/debug_kit.git app/Plugin/DebugKit
19
```
20
 
21
* Ensure the plugin is loaded in `app/Config/bootstrap.php` by calling `CakePlugin::load('DebugKit');`
22
* Include the toolbar component in your `app/Controller/AppController.php`:
23
```php
24
class AppController extends Controller {
25
         public $components = array('DebugKit.Toolbar');
26
}
27
```
28
* Set `Configure::write('debug', 1);` in `app/Config/core.php`.
29
* Make sure to remove the 'sql_dump' element from your layout (usually
30
  `app/View/Layouts/default.ctp`), if you want to experience the awesome that is
31
  the DebugKit SQL log.
32
 
33
### Using Composer
34
 
35
Ensure `require` is present in `composer.json`. This will install the plugin into `Plugin/DebugKit`:
36
 
37
```json
38
{
39
    "require": {
40
        "cakephp/debug_kit": "2.2.*"
41
    }
42
}
43
```
44
Consider using "require-dev" if you only want to include DebugKit for your development environment.
45
 
46
## Reporting Issues
47
 
48
If you have a problem with DebugKit please open an issue on [GitHub](https://github.com/cakephp/debug_kit/issues).
49
 
50
## Contributing
51
 
52
If you'd like to contribute to DebugKit, check out the
53
[roadmap](https://github.com/cakephp/debug_kit/wiki/roadmap) for any
54
planned features. You can [fork](https://help.github.com/articles/fork-a-repo)
55
the project, add features, and send [pull
56
requests](https://help.github.com/articles/using-pull-requests) or open
57
[issues](https://github.com/cakephp/debug_kit/issues).
58
 
59
## Versions
60
 
61
DebugKit has several releases, each compatible with different releases of
62
CakePHP. Use the appropriate version by downloading a tag, or checking out the
63
correct branch.
64
 
65
* `1.0, 1.1, 1.2` are compatible with CakePHP 1.2.x. These releases of DebugKit
66
  will not work with CakePHP 1.3. You can also use the `1.2-branch` for the mos
67
  recent updates and bugfixes.
68
* `1.3.0` is compatible with CakePHP 1.3.x only. It will not work with CakePHP
69
  1.2. You can also use the `1.3` branch to get the most recent updates and
70
  bugfixes.
71
* `2.0.0` is compatible with CakePHP 2.0.x only. It will not work with previous
72
  CakePHP versions.
73
* `2.2.0` is compatible with CakePHP 2.2.0 and greater. It will not work with
74
  older versions of CakePHP as this release uses new API's available in 2.2.
75
  You can also use the `master` branch to get the most recent updates.
76
* `2.2.x` are compatible with CakePHP 2.2.0 and greater. It is a necessary
77
  upgrade for people using CakePHP 2.4 as the naming conventions around loggers
78
  changed in that release.
79
 
80
# Documentation
81
 
82
## Toolbar Panels
83
 
84
The DebugKit Toolbar is comprised of several panels, which are shown by clicking the
85
CakePHP icon in the upper right-hand corner of your browser after DebugKit has been
86
installed and loaded. Each panel is comprised of a panel class and view element.
87
Typically, a panel handles the collection and display of a single type of information
88
such as Logs or Request information. You can choose to panels from the toolbar or add
89
your own custom panels.
90
 
91
### Built-in Panels
92
 
93
There are several built-in panels, they are:
94
 
95
 * **History** Allows access to previous request information, useful when
96
   debugging actions with redirects.
97
 * **Request** Displays information about the current request, GET, POST, Cake
98
   Parameters, Current Route information and Cookies if the `CookieComponent`
99
   is in you controller's components.
100
 * **Session** Display the information currently in the Session.
101
 * **Timer** Display any timers that were set during the request see
102
   `DebugKitDebugger` for more information. Also displays
103
   memory use at component callbacks as well as peak memory used.
104
 * **Sql Logs** Displays sql logs for each database connection.
105
 * **Log** Display any entries made to the log files this request.
106
 * **Variables** Display View variables set in controller.
107
 * **Environment** Display environment variables related to PHP + CakePHP.
108
 
109
## Configuration
110
 
111
The toolbar has a few configuration settings. Settings are passed in the component declaration like normal component configuration.
112
 
113
```php
114
public $components = array(
115
    'DebugKit.Toolbar' => array(/* array of settings */)
116
);
117
```
118
 
119
### Configuring Panels
120
 
121
You can customize the toolbar to show your custom panels or hide any built-in panel when adding it toolbar to your components.
122
```php
123
public $components = array('DebugKit.Toolbar' => array(
124
    'panels' => array('MyCustom', 'timer'=>false)
125
    )
126
);
127
```
128
 
129
Would display your custom panel and all built-in panels except the 'Timer' panel.
130
 
131
#### Controlling Panels
132
 
133
Using the panels key you can specify which panels you want to load, as well as the order in which you want the panels loaded.
134
```php
135
public $components = array(
136
        'DebugKit.Toolbar' => array('panels' => array('MyCustom', 'timer' => false))
137
);
138
```
139
 
140
Would add your custom panel `MyCustomPanel` to the toolbar and exclude the default `Timer` panel. In addition to choosing which panels you want, you can pass options into the `__construct` of the panels. For example the built-in `History` panel uses the `history` key to set the number of historical requests to track.
141
```php
142
public $components = array(
143
        'DebugKit.Toolbar' => array('history' => 10)
144
);
145
```
146
 
147
Would load the `History` panel and set its history level to 10. The `panels` key is not passed to the Panel constructor.
148
 
149
#### forceEnable
150
 
151
The `forceEnable` setting is new in DebugKit 1.1. It allows you to force the toolbar to display regardless of the value of `Configure::read('debug');`. This is useful when profiling an application with debug kit as you can enable the toolbar even when running the application in production mode.
152
 
153
#### autoRun
154
 
155
autoRun is a new configuration setting for DebugKit 1.2. It allows you to control whether or not the toolbar is displayed automatically or whether you would like to use a query string parameter to enable it. Set this configuration key to false to use query string parameter toggling of the toolbar.
156
```php
157
public $components = array(
158
    'DebugKit.Toolbar' => array('autoRun' => false)
159
);
160
```
161
 
162
When visiting a page you can add `?debug=true` to the url and the toolbar will be visible. Otherwise it will stay hidden and not execute.
163
 
164
## Developing Your Own Panels
165
 
166
You can create your own custom panels for DebugKit to help in debugging your applications.
167
 
168
### Panel Classes
169
 
170
Panel Classes simply need to be placed in`Panel` directory inside a `Lib` path. The filename should match the classname, so the class `MyCustomPanel` would be expected to have a filename of `app/Lib/Panel/MyCustomPanel.php`.
171
```php
172
 
173
App::uses('DebugPanel', 'DebugKit.Lib');
174
 
175
/**
176
 * My Custom Panel
177
 */
178
class MyCustomPanel extends DebugPanel {
179
        ...
180
}
181
```
182
See also the example `Test/test_app/Plugin/DebugkitTestPlugin/Lib/Panel/PluginTestPanel.php`.
183
 
184
Notice that custom panels are required to subclass the `DebugPanel` class. Panels can define the
185
`css` and `javascript` properties to include additional CSS or javascript on the page. Both
186
properties should be an array.
187
```php
188
class MyCustomPanel extends DebugPanel {
189
        public $javascript = array(
190
                '/my_plugin/js/custom_panel.js'
191
        );
192
}
193
```
194
 
195
### Callbacks
196
 
197
Panel objects have 2 callbacks, that allow them to hook into and introspect on the current request.
198
```php
199
startup(Controller $controller)
200
```
201
 
202
Each panel's `startup()` method is called during component `startup()` process. `$controller` is a reference to the current controller object.
203
```php
204
beforeRender(Controller $controller)
205
```
206
 
207
Much like `startup()` `beforeRender()` is called during the Component beforeRender() process. Again `$controller` is a reference to the current controller. Normally at this point you could do additional introspection on the controller. The return of a panels `beforeRender()` is automatically passed to the View by the Toolbar Component. Therefore, under normal use you do not need to explicitly set variables to the controller.
208
 
209
#### Example of beforeRender Callback
210
```php
211
/**
212
 * beforeRender callback - grabs request params
213
 *
214
 * @return array
215
 */
216
 public function beforeRender(Controller $controller) {
217
     return $controller->params;
218
 }
219
```
220
 
221
This would return cake's internal params array. The return of a panel's `beforeRender()` is available in you Panel element as `$content`
222
 
223
### Panel Elements
224
 
225
Each Panel is expected to have a view element that renders the content from the panel. The element name must be the underscored inflection of the class name. For example `SessionPanel` has an element named `session_panel.ctp`, and sqllogPanel has an element named `sqllog_panel.ctp`. These elements should be located in the root of your `View/Elements` directory.
226
 
227
#### Custom Titles and Elements
228
 
229
Panels should pick up their title and element name by convention. However, if you need to choose a custom element name or title, there are properties to allow that configuration.
230
 
231
- `$title` - Set a custom title for use in the toolbar. This title will be used as the panels button.
232
- `$elementName` - Set a custom element name to be used to render the panel.
233
 
234
### Panels as Cake Plugins
235
 
236
Panels provided by [Cake Plugins](http://book.cakephp.org/2.0/en/plugins.html) work almost entirely the same as other plugins, with one minor difference:  You must set `public $plugin` to be the name of the plugin directory, so that the panel's Elements can be located at render time.
237
```php
238
class MyCustomPanel extends DebugPanel {
239
    public $plugin = 'MyPlugin';
240
        ...
241
}
242
```
243
 
244
To use a plugin panel, use the common CakePHP dot notation for plugins.
245
```php
246
public $components = array('DebugKit.Toolbar' => array(
247
    'panels' => array('MyPlugin.MyCustom')
248
));
249
```
250
The above would load all the default panels as well as the custom panel from `MyPlugin`.
251
 
252
## Cache Engine
253
 
254
By default, DebugKit uses File as the engine for internal caching, but if you want to use another cache engine you can customize it by simply adding a cache key inside the components config array.
255
```php
256
public $components = array('DebugKit.Toolbar' => array(
257
        'cache' => array('engine' => 'Memcache', 'servers' => array('127.0.0.1:11211'))
258
        )
259
);
260
```
261
 
262
You can use any cache engine supported by CakePHP, the same way you set in both core.php and bootstrap.php files with the Cache::config() method.
263
 
264
## Viewing the Toolbar for AJAX Requests
265
 
266
When doing AJAX requests, you will not be able to see an HTML version of the toolbar. However, if you have a browser extension that supports FirePHP, you can view
267
the toolbar in your browser:
268
 
269
- [FirePHP 4 chrome](https://chrome.google.com/webstore/detail/firephp4chrome/gpgbmonepdpnacijbbdijfbecmgoojma)
270
- [FirePHP for chrome](https://chrome.google.com/webstore/detail/firephp-for-chrome/goajlbdffkligccnfgibeilhdnnpaead)
271
- [FirePHP for firefox](https://addons.mozilla.org/en-US/firefox/addon/firephp/)
272
 
273
Once you have installed the correct extension, you should see the toolbar data output on each ajax request.