Joc*_*hen 1 rest json zend-framework2
我阅读了几个教程,用ZF2创建一个安静的Web服务.我看到最后一次改变了ZF2如何处理版本2.0.4中发生的restful webservices.让我开始的最有希望的文章是:http: //dustint.com/post/543/getting-started-with-abstractrestfulcontroller
无论如何,我无法完成它,在我看来,在RestController.getList()中,我返回的JsonModel不能像预期的那样工作.由于我的调试调用,我可以识别我的RestController.getList() - 方法将被调用.所有相关代码都在我的github-repository中:https: //github.com/Jochen1980/EhcServer/blob/master/module/Application/src/Application/Controller/RestController.php
class RestController extends AbstractRestfulController{
public function indexAction(){
Debug::dump("indexAction()");
return new ViewModel();
}
public function getList() {
Debug::dump("getList()");
return new JsonModel(array(
array('name' => 'test'),
array('name' => 'second')
));
}
...
Run Code Online (Sandbox Code Playgroud)
目前我收到此错误消息:致命错误:未捕获异常'Zend\View\Exception\RuntimeException',消息'Zend\View\Renderer\PhpRenderer :: render:无法呈现模板"application/rest/get-list"; 解析器无法解析为第499行的C:\ xampp\htdocs\EhcServer\vendor\zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php中的文件
提前致谢!
你strategies需要在里面view_manager的module.config.php
也就是说,视图管理器部分应该如下所示
'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',
),
// let the view manager know which strategies to use
'strategies' => array(
'ViewJsonStrategy',
),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2011 次 |
| 最近记录: |