Last active
December 23, 2015 00:39
-
-
Save dweingart/6554643 to your computer and use it in GitHub Desktop.
Slim Framework - Routes that call different methods based on query args only
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 | |
// http://www.example.com/foo | |
$app->get('/foo', | |
// route middleware throws Pass exception based on query arg variables. | |
function() use ($app) | |
{ | |
$getVars = $app->request->params(); | |
if (isset($getVars['hello']) && ('world' == $getVars['hello'])) | |
{ | |
throw new \Slim\Exception\Pass; | |
} | |
}, function () | |
{ | |
echo '<p><b>Foo Was Called</b></p>'; | |
}); | |
// http://www.example.com/foo?hello=world | |
$app->get('/foo', | |
function () | |
{ | |
echo '<p><b>Hello, World</b></p>'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment