简体   繁体   中英

Zend Framework 1: Different Error-Layout and -scripts for each module

as the title indicates, I want to have different error views for each module in my Zend Framework-1-Projekt. It is not necessary to have a seperate error controller for each module, which I tried, I just want to use different layout-files, and if there is no error-Layout in a module use the default error view as fallback. Until now it always uses the "default" error controller and "default"-view-folder. Does anyone know how to achieve that? I'm kind of new in Zend Framework... So I apologize if it is a stupid question.

Try this

$module = $request->getModuleName();
if (file_exists(APPLICATION_PATH . '/layouts/' . $module . '_error.html')) {
    $module_err = $module . '_error'
    Zend_Layout::getMvcInstance()->setLayout($module_err );
} else {
   //use default layout
   .....
}  

When the exception is thrown from the module and then handled by ErrorHandler controller plugin and then dispatched to default error controller, the view object will have 2 scripts dirs set to look for views:

original module's and then the default one.

So all you need to do is to create module specific view script (say application/modules/moduleA/views/scripts/error/error.phtml ) and it will be used.

If it does not exist, then the default one ( application/views/scripts/error/error.phtml ) will be used.

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