用於多模組應用程式的 RESTful API 路由
// Define new router group
$api = new \Phalcon\Mvc\Router\Group([
'module' => 'api',
]);
$api->setPrefix('/api/v1');
// API routes (Maps to Cotnroller::Action)
$api->addGet('/users', 'Users::index');
$api->addGet('/users/search/{query}', 'Users::search');
$api->addGet('/users/{id:[0-9]+}', 'Users::fetch');
$api->addPost('/users', 'Users::add');
$api->addPut('/users/{id:[0-9]+}', 'Users::edit');
$api->addDelete('/users/{id:[0-9]+}', 'Users::delete');
// Add API routes to main router
$router->mount($api);
建立使用者的示例:
curl -i -X POST -d
'{"name": "John Snow", "title": "King of the North"}'
http://example.com/api/v1/users