简体   繁体   中英

How to remove default “Application” module from ZF2 Skeleton 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM