简体   繁体   中英

Diffrent settings in module.config.php for every module in zf2

I have got two modules: admin and application in first have:

'view_helper_config' => array(
        'flashmessenger' => array(
            'message_open_format'      => '<div%s><button data-dismiss="alert" class="close" type="button">×</button>',
            'message_separator_string' => '<br>',
            'message_close_string'     => '</div>'
        ),
    ),

in second have:

'view_helper_config' => array(
    'flashmessenger' => array(
        'message_open_format'      => '<ul%s><li>',
        'message_separator_string' => '<li></li>',
        'message_close_string'     => '</li></ul>'
    ),
),

and it's always merged. I would like to have on every module diffrent config. How can I do it?

Keep in mind that your module.config.php files act a bit like cascading style sheets in that the first one gets loaded and then the settings in the subsequent files either supplement or replace the settings that were loaded by the previous files. The module.config.php files get loaded in the order that the modules are listed in project\\config\\application.config . In other words, the statements that you have included in two different files are equivalent to listing them one after another in the same module.config.php .

There are several solutions to your question:

  1. Clone the helper by extending it and giving it a different name, and use different versions in different modules. (If you do this you might even be able to set the default HTML strings in the aliases and avoid setting them in module.config.php altogether).
  2. Set the HTML strings in your views rather than in module.config.php . Look at the documentation to learn how.
  3. Clone your layout.phtml and set the strings in there . The solution above requires that you set the HTML strings in each and every view that you create, but the documentation says you can set them in any .phtml . EdpModuleLayouts allows you to have separate, module-specific layouts; and you can create a different layout for each module and set your chosen HTML strings in each layout.
  4. Toggle HTML strings on and off with CSS classes . I use EdpModuleLayouts so that the skin for my admin module is strikingly different from the other module(s), and so I already have alternate CSS files for different modules. With these, it is possible to toggle HTML strings on and off. For your application you could put a class=”toggleFM” in relevant tags and set the CSS settings to display: hidden; accordingly so that in one module certain elements are rendered and in another module other elements are rendered. This is a convoluted solution, but it allows you to set the HTML strings in your module.config.php files if that's what you want to do.

EDIT

Also, take a look at your separator string. You probably want '</li><li>' and not '<li></li>' because the separator closes a list item and opens another.

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