Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to render template RuntimeException for AbstractRestfulController #34

Open
michalbundyra opened this issue Jan 15, 2020 · 4 comments

Comments

@michalbundyra
Copy link
Member

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


Originally posted by @jerv13 at zendframework/zend-mvc#3

@michalbundyra
Copy link
Member Author

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.


Originally posted by @rodmcnew at zendframework/zend-mvc#3 (comment)

@michalbundyra
Copy link
Member Author

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?!


Originally posted by @scroach at zendframework/zend-mvc#3 (comment)

@michalbundyra
Copy link
Member Author

@michalbundyra
Copy link
Member Author

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


Originally posted by @chaos0815 at zendframework/zend-mvc#3 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant