I am testing my zf2 restful api by sending an OPTIONS command to it but its going right into the action defined in the router and not the options() method.
Router:
'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(
),
),
),
),
),
),
),
Controller:
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;
}
}
When I sent an OPTIONS command to /api/some/execute it goes right into the execute action and not into the options method. Is there something I'm missing in the routing? I thought that sending any OPTIONS command would route it to options().
Thanks