2016-06-08 53 views
0

我有一定的困难,了解我如何使用Application类型的对象,而不是一个Micro的实现在一个单独的目录中的API。实现使用应用程序上下文API - 尔康

目前,当我尝试实施:

$application->get('/api/robots', function() { 

}); 

内我index.php内公开,在这里我创建:

$application = new Application($di);  

echo $application->handle()->getContent(); 

它总是将它们视为view controllers并要求controller。我想下面的文档创建一个简单的RESTful API,我结束了创建名为api其中micro index.php(遵循本教程中的API微应用的精确布局)住一个单独的文件夹,但在这一天结束时,我不断收到ApiController not found

我有点难住,任何澄清/简化将是非常有益的!

这里是教程:https://docs.phalconphp.com/en/latest/reference/tutorial-rest.html

回答

0

如果你喜欢使用Phalcon\Mvc\Application超过Phalcon\Mvc\Micro,你可以处理你的路由方式,你通常会相同。

$router = new Phalcon\Mvc\Router(); 

// route for a GET request (controller: ApiController, action: requestAction) 
$router->addGet('/api/request/{id}', [ 
    'controller' => 1, 
    'action'  => 2, 
]); 

// route for a DELETE request (controller: ApiController, action: removeAction) 
$router->addDelete('/api/remove/{id}', [ 
    'controller' => 1, 
    'action'  => 2, 
]); 

// this works the same for 
// $router->addPut(...) and $router->addPost(...) 

// other normal route 
$router->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', [ 
    'controller' => 1, 
    'action'  => 2, 
    'params'  => 3 
]);