Hey Guys,
I am currently in the process of building an API with ZF2 2.1 and I've
downloaded the Skeleton Application and built my module named /API/. I am
trying to figure out the best way to return 404 JSON response and routes
don't match and catch fatal errors and exceptions and respond with
appropriate JSON response.
Currently in my module directory I have /Application/ and /API/ modules.
The /API/ module is where my config and source is for my app.
In my /module/API/config/module.config.php I have the JsonViewStrategy
configured and returning JSON responses for requests
'view_manager' => array(
'strategies' => array(
'ViewJsonStrategy'
),
),
For the /module/Application/config/module.config.php, the view manager is
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ .
'/../view/layout/layout.phtml',
'application/index/index' => __DIR__ .
'/../view/application/index/index.phtml',
'error/404' => __DIR__ .
'/../view/error/404.phtml',
'error/index' => __DIR__ .
'/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
At this moment, when I hit http://localhost it returns the page "Welcome to
Zend Framework 2". When routes don't match, it returns the /
./view/error/404.phtml /form the /module/Application module.
When I remove the application module from module in
/config/application.config.php it complains giving this text error:
/Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with
message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template
"error"; resolver could not resolve to a file' in
/Users/abc/Sites/xyz/API/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php
on line 499/
What are some ways I can "map" the exception and 404 so that I can generate
a JSON response?
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Returning-JSON-for-404-and-for-exception-tp4660236.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]