Closed Huanga-IT-Solutions closed 1 year ago
You need to ensure that the "Json Rendering Strategy" is enabled in your MVC app.
Your configuration will need to include the following:
'view_manager' => [
'strategies' => [
'ViewJsonStrategy',
],
];
To be fair, I don't think that this is covered in the docs in either laminas-view or laminas-mvc.
Whilst this article is pretty old, it should still illustrate the same required configuration with a bit more context.
Hi George,
Thanks, that worked :)
BR, Valentin
@gsteel
To be fair, I don't think that this is covered in the docs in either laminas-view or laminas-mvc.
Please see: "Quick Start – Creating and Registering Alternate Rendering and Response Strategies":
You could also use the module configuration to add the strategies:
namespace Application; use Laminas\ModuleManager\Feature\ConfigProviderInterface; class Module implements ConfigProviderInterface { /** * Returns configuration to merge with application configuration * * @return array */ public function getConfig() { return [ /* ... */ 'view_manager' => [ /* ... */ 'strategies' => [ 'ViewJsonStrategy', ], ], ]; } }
Thanks @froschdesign 👍
The corresponding hint can also be found in the documentation of laminas-view: https://docs.laminas.dev/laminas-mvc/services/#default-configuration-options Not ideal but present.
Bug Report
Summary
Can't return a JsonModel in Controller. Laminas tries to render a View - Template. It seems that Laminas confuses the JsonModel for a ViewModel.
Current behavior
Code:
When I try to return a JsonModel, following fatal error message occurs:
Screenshot from 2023-10-23 12-25-08
How to reproduce
I'm using Docker / Docker - Compose. Here is my Docker / Docker - Compose - File:
Expected behavior
No Error Message, Return JSON - Response to Client.
Thanks for your Help :)