dougaoshang0237 2014-06-05 19:37
浏览 34
已采纳

如何从ZF2 Skeleton Application中删除默认的“Application”模块

I created a ZF2 REST web service, starting from the ZF2 Skeleton Application. I've created my own module, with my routes and a view strategy of ViewStrategyJson.

What I want to do is to remove the default "Application" module, so that the only module in my application is my own custom module, for my REST service.

I tried removing "Application" from the list of modules in application.config.php, making this change:

'modules' => array(
    'Application',
    'RestModule',
),

'modules' => array(
    'RestModule',
),

However, when I do this, all requests to my REST module now give me this 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 /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php:499

Stack trace:
#0 /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#1 /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#2 /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#3 /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#4 [internal function]: Zend\Mvc\View in /opt/lampp/htdocs/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php** on line 499

I feel like I must be missing something, somewhere, but I can't seem to find it. I would love some help/suggestions. Thanks.

  • 写回答

1条回答 默认 最新

  • doujiang7258 2014-06-07 11:38
    关注

    ZF2 Skeleton Application provides some basic bootstrapping operations in Module.php's onBootstrap() method such as attaching $eventManager instance to ModuleRouteListener, also represents some basic initial settings in module.config.php.

    Don't forget to do same things in your RestModule before removing Application module.

    If you migrated the view_manager settings from Application module's module.config.php to your RestModule's one too, make sure that it has three important keys related with error cases:

    'not_found_template'   => 'error/404',
    'exception_template'   => 'error/index',
    'template_map' => array('
        'layout/layout'  => __DIR__ . '/../view/layout/layout.phtml',
        'error/404'      => __DIR__ . '/../view/error/404.phtml',
        'error/index'    => __DIR__ . '/../view/error/index.phtml',
        ),
    

    Since this keys represents view paths to correctly render exceptions and other erros, you have to move Application/view/error and Application/view/layout folders too into your RestModule or change these settings to suit your needs.

    After these minor details, there is nothing wrong with the removing the Application module which provided by skeleton app.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图