1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-06-10 08:05:49 +02:00
php-debugbar/docs/ajax-and-stack.html
2013-09-28 12:01:21 -04:00

390 lines
10 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>PHP Debug Bar</title>
<link type="text/css" rel="stylesheet" href="/docs/assets/css/reset.css">
<link type="text/css" rel="stylesheet" href="http://yandex.st/highlightjs/6.1/styles/sunburst.min.css">
<link type="text/css" rel="stylesheet" href="/docs/assets/css/docs.css">
<link type="text/css" rel="stylesheet" href="/docs/assets/css/print.css" media="print">
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript" src="/docs/assets/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="http://yandex.st/highlightjs/6.1/highlight.min.js"></script>
<script type="text/javascript" src="/docs/assets/js/lunr.min.js"></script>
<script type="text/javascript">var BASE_URL = "/docs/";</script>
<script type="text/javascript" src="/docs/assets/js/viewer.js"></script>
</head>
<body>
<div id="page">
<a name="top" />
<header id="header">
<h1><a href="/docs/">PHP Debug Bar</a></h1>
</header>
<div id="sidebar">
<form action="/docs/search.html"><input id="search" type="text" placeholder="Search" name="q" /></form>
<nav id="toc">
<ol>
<li>
<a href="/docs/readme.html#php-debug-bar">PHP Debug Bar</a>
<ol>
<li>
<a href="/docs/readme.html#installation">Installation</a>
</li>
<li>
<a href="/docs/readme.html#quick-start">Quick start</a>
</li>
</ol>
</li>
<li>
<a href="/docs/data-collectors.html#collecting-data">Collecting Data</a>
<ol>
<li>
<a href="/docs/data-collectors.html#using-collectors">Using collectors</a>
</li>
<li>
<a href="/docs/data-collectors.html#creating-collectors">Creating collectors</a>
</li>
</ol>
</li>
<li>
<a href="/docs/rendering.html#rendering">Rendering</a>
<ol>
<li>
<a href="/docs/rendering.html#assets">Assets</a>
</li>
<li>
<a href="/docs/rendering.html#managing-jquery-conflicts">Managing jQuery conflicts</a>
</li>
<li>
<a href="/docs/rendering.html#the-javascript-object">The javascript object</a>
</li>
</ol>
</li>
<li>
<a href="/docs/ajax-and-stack.html#ajax-and-stacked-data">AJAX and Stacked data</a>
<ol>
<li>
<a href="/docs/ajax-and-stack.html#ajax">AJAX</a>
</li>
<li>
<a href="/docs/ajax-and-stack.html#stacked-data">Stacked data</a>
</li>
</ol>
</li>
<li>
<a href="/docs/base-collectors.html#base-collectors">Base collectors</a>
<ol>
<li>
<a href="/docs/base-collectors.html#messages">Messages</a>
</li>
<li>
<a href="/docs/base-collectors.html#timedata">TimeData</a>
</li>
<li>
<a href="/docs/base-collectors.html#exceptions">Exceptions</a>
</li>
<li>
<a href="/docs/base-collectors.html#pdo">PDO</a>
</li>
<li>
<a href="/docs/base-collectors.html#requestdata">RequestData</a>
</li>
<li>
<a href="/docs/base-collectors.html#config">Config</a>
</li>
<li>
<a href="/docs/base-collectors.html#aggregatedcollector">AggregatedCollector</a>
</li>
<li>
<a href="/docs/base-collectors.html#others">Others</a>
</li>
</ol>
</li>
<li>
<a href="/docs/bridge-collectors.html#bridge-collectors">Bridge collectors</a>
<ol>
<li>
<a href="/docs/bridge-collectors.html#cachecache">CacheCache</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#doctrine">Doctrine</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#monolog">Monolog</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#propel">Propel</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#slim">Slim</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#swift-mailer">Swift Mailer</a>
</li>
<li>
<a href="/docs/bridge-collectors.html#twig">Twig</a>
</li>
</ol>
</li>
<li>
<a href="/docs/storage.html#storage">Storage</a>
<ol>
<li>
<a href="/docs/storage.html#available-storage">Available storage</a>
</li>
<li>
<a href="/docs/storage.html#creating-your-own-storage">Creating your own storage</a>
</li>
<li>
<a href="/docs/storage.html#request-id-generator">Request ID generator</a>
</li>
</ol>
</li>
<li>
<a href="/docs/openhandler.html#open-handler">Open handler</a>
<ol>
</ol>
</li>
<li>
<a href="/docs/http-drivers.html#http-drivers">HTTP drivers</a>
<ol>
</ol>
</li>
<li>
<a href="/docs/javascript-bar.html#javascript-bar">Javascript Bar</a>
<ol>
<li>
<a href="/docs/javascript-bar.html#tabs-and-indicators">Tabs and indicators</a>
</li>
<li>
<a href="/docs/javascript-bar.html#data-mapping">Data mapping</a>
</li>
<li>
<a href="/docs/javascript-bar.html#datasets">Datasets</a>
</li>
<li>
<a href="/docs/javascript-bar.html#widgets">Widgets</a>
</li>
<li>
<a href="/docs/javascript-bar.html#custom-tabs-and-indicators">Custom tabs and indicators</a>
</li>
<li>
<a href="/docs/javascript-bar.html#openhandler">OpenHandler</a>
</li>
</ol>
</li>
</ol>
</nav>
<nav id="links">
<ul>
</ul>
</nav>
</div>
<div id="content">
<a name="ajax-and-stacked-data"></a><h1>AJAX and Stacked data</h1>
<a name="ajax"></a><h2>AJAX</h2>
<p>As mentioned in the previous chapter, if you are performing AJAX requests
which return HTML content, you can use <code>JavascriptRenderer::render(false)</code>.</p>
<p>In the case you are sending back non-HTML data (eg: JSON), the DebugBar can
send data to the client using HTTP headers using the <code>sendDataInHeaders()</code> method
(no need to use the <code>JavascriptRenderer</code>):</p>
<pre><code>$debugbar = new DebugBar();
// ...
$debugbar-&gt;sendDataInHeaders();</code></pre>
<p>On the client side, an instance of <code>PhpDebugBar.AjaxHandler</code> will
parse the headers and add the dataset to the debugbar.</p>
<p>The AjaxHandler automatically binds to jQuery&#39;s <em>ajaxComplete</em> event
so if you are using jQuery, you have nothing to configure.</p>
<p>If you&#39;re not using jQuery, you can call <code>AjaxHandler.handle(xhr)</code>.
If you are using the <code>JavascriptRenderer</code> initialization, the instance
of <code>AjaxHandler</code> is stored in the <code>ajaxHandler</code> property of the <code>DebugBar</code> object.</p>
<pre><code>debugbar.ajaxHandler.handle(xhr);</code></pre>
<p>If you are sending a lot of data through headers, it may cause problems
with your browser. Instead you can use a storage handler (see Storage chapter)
and the open handler (see Open Handler chapter) to load the data after an ajax
request. Use true as the first argument of <code>sendDataInHeaders()</code>.</p>
<pre><code>$debugbar = new DebugBar();
// define a storage
$debugbar-&gt;setStorage(new DebugBar\Storage\FileStorage(&#39;/path/to/storage&#39;));
// define the open handler url
$renderer = $debugbar-&gt;getJavascriptRenderer();
$renderer-&gt;setOpenHandlerUrl(&#39;open.php&#39;);
// ...
$debugbar-&gt;sendDataInHeaders(true);</code></pre>
<a name="stacked-data"></a><h2>Stacked data</h2>
<p>Some times you need to collect data about a request but the page won&#39;t actually
be displayed. The best example of that is during a redirect. You can use the
debug bar storage mechanism to store the data and re-open it later but it can
be cumbersome while testing a redirect page.</p>
<p>The solution is to use stacked data. The debug bar can temporarily store the
collected data in the session until the next time it will be displayed.
Simply call <code>DebugBar::stackData()</code> instead of rendering the debug bar.</p>
<p>PHP&#39;s session must be started before using this feature.</p>
<p>Note: The stacked data feature will use the storage mechanism of it&#39;s enabled
instead of storing the data in the session.</p>
<pre><code>$debugbar = new DebugBar();
// ...
$debugbar-&gt;stackData();</code></pre>
<p>Stacked data are rendered each time the debug bar is rendered using the
<code>JavascriptRenderer</code>.</p>
</div>
<footer id="footer">
Powered by <a href="http://github.com/maximebf/beautiful-docs">beautiful-docs</a> -
<a href="#top">Back to top</a> - <a href="/docs/all.html">Everything on a single page</a>
- <a href="?print=1">Print current page</a> - <a href="/docs/all.html?print=1">Print all pages</a>
</footer>
</div>
</body>
</html>