我正在通過向它發送一個OPTIONS命令來測試我的zf2 restful api,但它直接進入在路由器中定義的動作而不是options()方法。ZF2 Restful API非路由選項方法
路由器:
'router' => array(
'routes' => array(
'edatafeed' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/api',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:controller[/:action][/]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
控制器:
class SomeController extends ApiController
{
protected $dm;
private function getDm()
{
$this->dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
}
public function executeAction()
{
return new JsonModel(array(
'ok' => false,
'data' => null,
));
}
}
ApiController:
class ApiController extends AbstractRestfulController
{
protected function methodNotAllowed()
{
$this->response->setStatusCode(405);
throw new \Exception('Method Not Allowed');
}
public function options()
{
$response = $this->getResponse();
$headers = $response->getHeaders();
$headers->addHeaderLine('Allow', implode(',', array(
'GET',
'POST',
)))
->addHeaderLine('Content-Type','application/json; charset=utf-8');
return $response;
}
}
當我發送的OPTIONS命令/ API /一些/執行它進入右入執行行動,而不是進入期權方法。在路由中是否有我缺少的東西?我認爲發送任何OPTIONS命令會將它路由到options()。
感謝