<h2><aclass="toc-backref"href="#id1">Replace var_dump</a><aclass="headerlink"href="#replace-var-dump"title="Permalink to this headline">¶</a></h2>
<p>While using XDebug and a good IDE can be indispensable to debug your application, sometimes a quick <codeclass="docutils literal"><spanclass="pre">var_dump()</span></code> is
all you need. CodeIgniter makes that even better by bundling in the excellent <aclass="reference external"href="https://raveren.github.io/kint/">Kint</a>
debugging tool for PHP. This goes way beyond your usual tool, providing many alternate pieces of data, like formatting
timestamps into recognizable dates, showing you hexcodes as colors, display array data like a table for easy reading,
and much, much more.</p>
<divclass="section"id="enabling-kint">
<h3><aclass="toc-backref"href="#id2">Enabling Kint</a><aclass="headerlink"href="#enabling-kint"title="Permalink to this headline">¶</a></h3>
<p>By default, Kint is enabled in <strong>development</strong> and <strong>testing</strong> environments only. This can be altered by modifying
the <codeclass="docutils literal"><spanclass="pre">$useKint</span></code> value in the environment configuration section of the main <strong>index.php</strong> file:</p>
<h3><aclass="toc-backref"href="#id3">Using Kint</a><aclass="headerlink"href="#using-kint"title="Permalink to this headline">¶</a></h3>
<p><strong>d()</strong></p>
<p>The <codeclass="docutils literal"><spanclass="pre">d()</span></code> method dumps all of the data it knows about the contents passed as the only parameter to the screen, and
<p>This method is identical to <codeclass="docutils literal"><spanclass="pre">d()</span></code>, except that it also <codeclass="docutils literal"><spanclass="pre">dies()</span></code> and no further code is executed this request.</p>
<p><strong>trace()</strong></p>
<p>This provides a backtrace to the current execution point, with Kint’s own unique spin:</p>
<p>For more information, see <aclass="reference external"href="https://kint-php.github.io/kint//">Kint’s page</a>.</p>
</div>
</div>
<divclass="section"id="the-debug-toolbar">
<h2><aclass="toc-backref"href="#id4">The Debug Toolbar</a><aclass="headerlink"href="#the-debug-toolbar"title="Permalink to this headline">¶</a></h2>
<p>The Debug Toolbar provides at-a-glance information about the current page request, including benchmark results,
queries you have run, request and response data, and more. This can all prove very useful during development
to help you debug and optimize.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">The Debug Toolbar is still under construction with several planned features not yet implemented.</p>
</div>
<divclass="section"id="enabling-the-toolbar">
<h3><aclass="toc-backref"href="#id5">Enabling the Toolbar</a><aclass="headerlink"href="#enabling-the-toolbar"title="Permalink to this headline">¶</a></h3>
<p>The toolbar is enabled by default in any environment <em>except</em> production. It will be shown whenever the
constant CI_DEBUG is defined and it’s value is positive. This is defined in the boot files (i.e.
application/Config/Boot/development.php) and can be modified there to determine what environments it shows
itself in.</p>
<p>The toolbar itself is displayed as an <aclass="reference internal"href="../incoming/filters.html"><spanclass="doc">After Filter</span></a>. You can stop it from ever
running by removing it from the <codeclass="docutils literal"><spanclass="pre">$globals</span></code> property of <strong>application/Config/Filters.php</strong>.</p>
<divclass="section"id="choosing-what-to-show">
<h4>Choosing What to Show<aclass="headerlink"href="#choosing-what-to-show"title="Permalink to this headline">¶</a></h4>
<p>CodeIgniter ships with several Collectors that, as the name implies, collect data to display on the toolbar. You
can easily make your own to customize the toolbar. To determine which collectors are shown, again head over to
<p>Comment out any collectors that you do not want to show. Add custom Collectors here by providing the fully-qualified
class name. The exact collectors that appear here will affect which tabs are shown, as well as what information is
shown on the Timeline.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<pclass="last">Some tabs, like Database and Logs, will only display when they have content to show. Otherwise, they
are removed to help out on smaller displays.</p>
</div>
<p>The Collectors that ship with CodeIgniter are:</p>
<ulclass="simple">
<li><strong>Timers</strong> collects all of the benchmark data, both by the system and by your application.</li>
<li><strong>Database</strong> Displays a list of queries that all database connections have performed, and their execution time.</li>
<li><strong>Logs</strong> Any information that was logged will be displayed here. In long-running systems, or systems with many items being logged, this can cause memory issues and should be disabled.</li>
<li><strong>Views</strong> Displays render time for views on the timeline, and shows any data passed to the views on a separate tab.</li>
<li><strong>Cache</strong> Will display information about cache hits and misses, and execution times.</li>
<li><strong>Files</strong> displays a list of all files that have been loaded during this request.</li>
<li><strong>Routes</strong> displays information about the current route and all routes defined in the system.</li>
</ul>
</div>
</div>
<divclass="section"id="setting-benchmark-points">
<h3><aclass="toc-backref"href="#id6">Setting Benchmark Points</a><aclass="headerlink"href="#setting-benchmark-points"title="Permalink to this headline">¶</a></h3>
<p>In order for the Profiler to compile and display your benchmark data you must name your mark points using specific syntax.</p>
<p>Please read the information on setting Benchmark points in the <aclass="reference internal"href="benchmark.html"><spanclass="doc">Benchmark Library</span></a> page.</p>
<h3><aclass="toc-backref"href="#id7">Creating Custom Collectors</a><aclass="headerlink"href="#creating-custom-collectors"title="Permalink to this headline">¶</a></h3>
<p>Creating custom collectors is a straightforward task. You create a new class, fully-namespaced so that the autoloader
can locate it, that extends <codeclass="docutils literal"><spanclass="pre">CodeIgniter\Debug\Toolbar\Collectors\BaseCollector</span></code>. This provides a number of methods
that you can override, and has four required class properties that you must correctly set depending on how you want
<p><strong>$hasTimeline</strong> should be set to <codeclass="docutils literal"><spanclass="pre">true</span></code> for any Collector that wants to display information in the toolbar’s
timeline. If this is true, you will need to implement the <codeclass="docutils literal"><spanclass="pre">formatTimelineData()</span></code> method to format and return the
data for display.</p>
<p><strong>$hasTabContent</strong> should be <codeclass="docutils literal"><spanclass="pre">true</span></code> if the Collector wants to display its own tab with custom content. If this
is true, you will need to provide a <codeclass="docutils literal"><spanclass="pre">$title</span></code>, implement the <codeclass="docutils literal"><spanclass="pre">display()</span></code> method to render out tab’s contents,
and might need to implement the <codeclass="docutils literal"><spanclass="pre">getTitleDetails()</span></code> method if you want to display additional information just
to the right of the tab content’s title.</p>
<p><strong>$hasVarData</strong> should be <codeclass="docutils literal"><spanclass="pre">true</span></code> if this Collector wants to add additional data to the <codeclass="docutils literal"><spanclass="pre">Vars</span></code> tab. If this
is true, you will need to implement the <codeclass="docutils literal"><spanclass="pre">getVarData()</span></code> method.</p>
<p><strong>$title</strong> is displayed on open tabs.</p>
<divclass="section"id="displaying-a-toolbar-tab">
<h4>Displaying a Toolbar Tab<aclass="headerlink"href="#displaying-a-toolbar-tab"title="Permalink to this headline">¶</a></h4>
<p>To display a toolbar tab you must:</p>
<olclass="arabic simple">
<li>Fill in <codeclass="docutils literal"><spanclass="pre">$title</span></code> with the text displayed as both the toolbar title and the tab header.</li>
<li>Set <codeclass="docutils literal"><spanclass="pre">$hasTabContent</span></code> to <codeclass="docutils literal"><spanclass="pre">true</span></code>.</li>
<li>Implement the <codeclass="docutils literal"><spanclass="pre">display()</span></code> method.</li>
<li>Optionally, implement the <codeclass="docutils literal"><spanclass="pre">getTitleDetails()</span></code> method.</li>
</ol>
<p>The <codeclass="docutils literal"><spanclass="pre">display()</span></code> creates the HTML that is displayed within the tab itself. It does not need to worry about
the title of the tab, as that is automatically handled by the toolbar. It should return a string of HTML.</p>
<p>The <codeclass="docutils literal"><spanclass="pre">getTitleDetails()</span></code> method should return a string that is displayed just to the right of the tab’s title.
it can be used to provide additional overview information. For example, the Database tab displays the total
number of queries across all connections, while the Files tab displays the total number of files.</p>
</div>
<divclass="section"id="providing-timeline-data">
<h4>Providing Timeline Data<aclass="headerlink"href="#providing-timeline-data"title="Permalink to this headline">¶</a></h4>
<p>To provide information to be displayed in the Timeline you must:</p>
<olclass="arabic simple">
<li>Set <codeclass="docutils literal"><spanclass="pre">$hasTimeline</span></code> to <codeclass="docutils literal"><spanclass="pre">true</span></code>.</li>
<li>Implement the <codeclass="docutils literal"><spanclass="pre">formatTimelineData()</span></code> method.</li>
</ol>
<p>The <codeclass="docutils literal"><spanclass="pre">formatTimelineData()</span></code> method must return an array of arrays formatted in a way that the timeline can use
it to sort it correctly and display the correct information. The inner arrays must include the following information:</p>
<spanclass="s1">'name'</span><spanclass="o">=></span><spanclass="s1">''</span><spanclass="p">,</span><spanclass="c1">// Name displayed on the left of the timeline</span>
<spanclass="s1">'component'</span><spanclass="o">=></span><spanclass="s1">''</span><spanclass="p">,</span><spanclass="c1">// Name of the Component listed in the middle of timeline</span>
<spanclass="s1">'start'</span><spanclass="o">=></span><spanclass="mf">0.00</span><spanclass="p">,</span><spanclass="c1">// start time, like microtime(true)</span>
<spanclass="s1">'duration'</span><spanclass="o">=></span><spanclass="mf">0.00</span><spanclass="c1">// duration, like mircrotime(true) - microtime(true)</span>
<spanclass="p">];</span>
</pre></div>
</div>
</div>
<divclass="section"id="providing-vars">
<h4>Providing Vars<aclass="headerlink"href="#providing-vars"title="Permalink to this headline">¶</a></h4>
<p>To add data to the Vars tab you must:</p>
<olclass="arabic simple">
<li>Set <codeclass="docutils literal"><spanclass="pre">$hasVarData</span></code> to <codeclass="docutils literal"><spanclass="pre">true</span></code></li>
<p>The <codeclass="docutils literal"><spanclass="pre">getVarData()</span></code> method should return an array containing arrays of key/value pairs to display. The name of the
outer array’s key is the name of the section on the Vars tab:</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.