Closed seaneble closed 7 years ago
There's little in the way of documentation for or recent information on AbstractRestfulController so I did this: using the latest version of the skeleton, I added a route to the module config:
'ping' => [
'type' => Segment::class,
'options' => [
'route' => '/ping[/:id]',
'defaults' => [
'controller' => Controller\PingController::class,
],
],
],
And added PingController:
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
class PingController extends AbstractRestfulController
{
public function getList()
{
return [
'now' => date(\DateTime::ISO8601)
];
}
}
(and added that controller to the controller factory)
... and it's "working". I dump the RouteMatch from inside getList and I get this:
Zend\Router\Http\RouteMatch Object
(
[length:protected] => 5
[params:protected] => Array
(
[controller] => Application\Controller\PingController
)
[matchedRouteName:protected] => ping
)
However, I also get a Zend\View runtime exception:
Unable to render template "application/ping/get-list"; resolver could not resolve to a file
I added the ViewJsonStrategy to the view manager but still received the same error. Maybe this stopped working way back when renderer selection based on Accept header was removed from those strategies (PR)? Or maybe I'm just not configuring the controller properly. In either case, AbstractRestfulController probably should be updated to use AcceptableViewModelSelector.
A quick Google didn't turn up any recent articles or mentions of AbstractRestfulController. I suspect that people have long since moved on to packages like ZfrRest or zf-rest or even rolling their own (eg: zend-router can do routing based on HTTP Method)
Router does not set parameters on its own, none of the zend-mvc versions have 'index'
string either.
It is either from route configuration or some user registered listener in mvc application
The RESTful controller of MVC knows two different behaviours:
action
returned by the router and dispatch to thisFor me, using the latest and greatest versions of both components, this is a problem. For some reason, the router always sets the
action
key of theRouteMatch
, so RESTful actions are never executed.This it the RouteMatch I get for
http://somedomain/
:The respective config is this:
I also tried to overwrite the
index
key deliberately by setting it tobut the RouteMatch always stays the same. Why? Is it me or the code?
Any help is very welcome.