Last active
August 29, 2015 14:27
-
-
Save Phunky/06afff1c77b903b110b8 to your computer and use it in GitHub Desktop.
What is the best way to allow me to pass data down to my views for all routes via middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Middleware for all requests | |
$app->add(function ($request, $response, $next) use ($container) { | |
if ($request->hasHeader('HTTP_X_PJAX')) { | |
// Here is where I would like to define an arg that can | |
// be passed down to my views for all requests | |
} | |
$response = $next($request, $response); | |
return $response; | |
}); | |
$app->get('/{route}', function($request, $response, $args) { | |
$template = $args['route'] . '.twig'; | |
// Goal of middleware is to replace done this in each route. | |
if ($request->hasHeader('HTTP_X_PJAX')) { | |
$args['isPjax'] = true; | |
} | |
return $this->view->render($response, $template, $args); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment