Created
May 6, 2013 18:00
-
-
Save phalcon/5526846 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| /** | |
| * @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