zend-mvc icon indicating copy to clipboard operation
zend-mvc copied to clipboard

Unable to render template RuntimeException for AbstractRestfulController

Open jerv13 opened this issue 10 years ago • 5 comments
trafficstars

I get an unable to render template error when i do not over-ride the AbstractRestfulController method.

By default, the response code is set and an array is returned which appears to be picked up and rendered using the default render strategy.

Would it be a good idea to set the response content and return the response or is there something I am missing in the configuration.

I would just like some feedback on this before I make a pull request.

Thanks,

James

jerv13 avatar May 26 '15 22:05 jerv13

I've ran into this issue many times as well and haven't found a good solution.

One way to recreate this is to extend the AbstractRestfulController and implement the get() action but not the getList() action. Then when you go to the getList route, you get a "template not found" error instead of a "Method Not Allowed" response like any other framework gives.

It doesn't make sense for me to have to create a "module-name/controller-name/get-list.phtml" template for every rest controller I create when I don't even want to implement "getList" functionality.

rodmcnew avatar May 27 '15 15:05 rodmcnew

I've stumbled across the same problem as I am currently trying to implement a REST API with ZF2. I registered the ViewJsonStrategy in my module and expected the AbstractRestfulController to return JSON-Based error-responses for unimplemented methods.

Afte some research I found out that the JsonStrategy has been changed long ago in 2.0.4 to only return JSON if a JsonModel has been explicitely returned. http://framework.zend.com/blog/zend-framework-2-0-4-released.html

So in my understanding the AbstractRestfulController shouldn't return plain arrays in the pre-implemented methods but JsonModel containing the array. This would produce something like this:

{"content":"Method Not Allowed"}

Am I right?!

scroach avatar Dec 09 '15 13:12 scroach

https://github.com/karborator/zend-mvc

karborator avatar Jun 21 '16 21:06 karborator

Is there a reason why AbstractRestfulController returns an array in the pre-implemented methods instead of an JsonModel object?

chaos0815 avatar Oct 04 '17 09:10 chaos0815

This repository has been closed and moved to laminas/laminas-mvc; a new issue has been opened at https://github.com/laminas/laminas-mvc/issues/34.

michalbundyra avatar Jan 15 '20 19:01 michalbundyra