Thursday, 29 August 2013

Redirect POST Request in RESTful Controller - Zend Framework2

Redirect POST Request in RESTful Controller - Zend Framework2

After getting used to the RESTful Web Services in Zend Framework2, I
encountering a typical redirect problem when dealing with POST Request.
The problem is that I have furnished an extra action in my indexController
which extends AbstractRestfulController for the POST Request. But when
testing the URI in Simple Restful Client, I found out that the request is
automatically routed to the create method in the indexController.
Is there a way how I can forcefully redirect the POST Request to one of
the actions which I wanted to that is set in the routes in
module.config.php file
Well here is my indexController:
<?php
namespace Project\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\Mvc\MvcEvent as Event;
use Zend\View\Model\JsonModel as Json;
use XmlStrategy\View\Model\XmlModel as Xml;
class IndexController extends AbstractRestfulController
{
public function getList ()
{
;
}
public function get ($id)
{
;
}
public function addAction ()
{
return $this->create(array(
'test' => "Test",
));
}
public function update ($id, $data)
{
;
}
public function create ($data)
{
;
}
public function delete ($id)
{
;
}
}
This is how im furnishing the routes
<?php
namespace Project;
return array(
'router' => array(
'routes' => array(
'home' => array(
'child_routes' => array(
'project' => array(
'type' => "Segment",
'options' => array(
'route' => "/project",
'defaults' => array(
'controller' =>
"Project\Controller\Index",
),
),
'may_terminate' => true,
'child_routes' => array(
'add' => array(
'type' => "Segment",
'options' => array(
'route' => "/add",
'defalults' => array(
'contoller' =>
"Project\Controller\Index",
'action' => "add",
),
),
'may_terminate' => true,
),
),
),
),
),
),
),
'view_manager' => array(
'strategies' => array(
"ViewJsonStrategy",
"ViewXMLStrategy",
),
),
);
But as described, when the URI with POST Request
www.myproject.com/project/add, i can see that it is redirected to the
create action in my controller
This is the error "Zend\View\Renderer\PhpRenderer::render: Unable to
render template "project/index/create"; resolver could not resolve to a
file"
Any help would be appreciated.
Thanks

No comments:

Post a Comment