Last active
August 23, 2016 14:04
-
-
Save cereal-s/5d5e8ecca4baa335b49d90bc1f782bc8 to your computer and use it in GitHub Desktop.
_route() function for SlimPHP 3.4.2, it returns the path for the named route
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 | |
if( ! function_exists('_route')) | |
{ | |
/** | |
* Return the path for the named route | |
* | |
* @see http://www.slimframework.com/docs/objects/router.html#route-names | |
* @param string $name | |
* @param array $parameters | |
* @return mixed | |
*/ | |
function _route($name = '', $parameters = []) | |
{ | |
global $app; | |
if($app instanceof Slim\App) | |
return $app->getContainer() | |
->get('router') | |
->pathFor($name, $parameters); | |
return FALSE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If in routes.php there is a route named fruit.index, like in this example:
$app->get('/fruit/{name}', '\App\Controllers\FruitController:index')->setName('fruit.index');
And in the view we want to print the path:
echo _route('fruit.index', ['name' => 'fuji_apples']);
The result will be
/fruit/fuji_apples
.