Skip to content

Instantly share code, notes, and snippets.

@phalcon
Created May 6, 2013 18:00
Show Gist options
  • Select an option

  • Save phalcon/5526846 to your computer and use it in GitHub Desktop.

Select an option

Save phalcon/5526846 to your computer and use it in GitHub Desktop.
<?php
/**
* @RoutePrefix("/users")
*/
class UsersController
{
/**
* @Get('/')
*/
public function indexAction()
{
echo 'Hello world'; //works perfect!!!
}
/**
* @Route('/{id:[0-9]+}', methods="GET", name="users-view")
*/
public function viewAction($id)
{
echo $id; // Don't work via '/users/100' URL. But it works perfect via /users/view/100
}
}
$di = new Phalcon\DI\FactoryDefault();
$di['router'] = function() {
//Use the annotations router
$router = new \Phalcon\Mvc\Router\Annotations(false);
$router->addResource('Users');
return $router;
};
$router = $di['router'];
$test = array('/users', '/users/100', '/users/view/100');
foreach ($test as $uri) {
$router->handle($uri);
if ($router->wasMatched()) {
echo 'Controller = ', $router->getControllerName(), '<br>';
echo 'Action = ', $router->getActionName(), '<br>';
echo 'Parameters = ', print_r($router->getParams(), true), '<br>';
} else {
echo $uri, ' was not matched', '<br>';
}
echo '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment