Skip to content

Instantly share code, notes, and snippets.

@phalcon
Last active December 11, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phalcon/4543132 to your computer and use it in GitHub Desktop.
Save phalcon/4543132 to your computer and use it in GitHub Desktop.
<?php
//...
$di->set('annotations', function(){
//In development mode the memory adapter could be used
//it will read the annotations every time requested
//other adapter would store the parsed annotations in files/shared memory, etc
return new Phalcon\Annotations\Adapter\Memory();
});
$di->set('router', function() {
//Use the annotations router
$router = new \Phalcon\Mvc\Router\Annotations();
//This always read routes from RobotsController
//This will autoload that class and automatically will create the routes based
//on its annotations
$router->addResource('Robots');
//This will do the same as above but only if the handled uri starts with /robots
$router->addResource('Robots', '/robots');
return $router;
});
<?php
/**
* @RoutePrefix("/robots")
*/
class RobotsController extends Phalcon\Mvc\Controller
{
/**
* @Get("/")
*/
public function indexAction()
{
}
/**
* @Get("/edit/{id:[0-9]+}", name="edit-robot")
*/
public function editAction($id)
{
}
/**
* @Route("/save", methods={"POST", "PUT"}, name="save-robot")
*/
public function saveAction()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment