composer require maximebf/debugbar
composer require kriswallsmith/assetic
dependencies.php
...
// PHP Debug Bar
$container['debugBar'] = function($c) {
$debugbar = new StandardDebugBar();
$debugbar->addCollector(new DebugBar\Bridge\MonologCollector($c['logger']));
$renderer = $debugbar->getJavascriptRenderer();
$renderer->setIncludeVendors(false);
return $debugbar;
};
...
routes.php
use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;
return function (App $app) {
$container = $app->getContainer();
$app->get('/[{name}]', function (Request $request, Response $response, array $args) use ($container) {
$debugbar = $container["debugBar"];
$debugbar["messages"]->addMessage("hello world!");
// Sample log message
$container->get('logger')->info("Slim-Skeleton '/' route");
// Render index view
return $container->get('renderer')->render($response, 'index.phtml', array_merge($args, [
"debugbarRenderer"=>$debugbar->getJavascriptRenderer()
]));
});
};
index.phtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Slim 3</title>
<link href='//fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<style>
body {
margin: 50px 0 0 0;
padding: 0;
width: 100%;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: center;
color: #aaa;
font-size: 18px;
}
h1 {
color: #719e40;
letter-spacing: -3px;
font-family: 'Lato', sans-serif;
font-size: 100px;
font-weight: 200;
margin-bottom: 0;
}
+ <?php $debugbarRenderer->dumpCssAssets(); ?>
</style>
+ <script type="text/javascript">
+ <?php $debugbarRenderer->dumpJsAssets(); ?>
+ </script>
</head>
<body>
<h1>Slim</h1>
<div>a microframework for PHP</div>
<?php if (isset($name)) : ?>
<h2>Hello <?= htmlspecialchars($name); ?>!</h2>
<?php else: ?>
<p>Try <a href="http://www.slimframework.com">SlimFramework</a></p>
<?php endif; ?>
+ <?php echo $debugbarRenderer->render() ?>
</body>
</html>