Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:53:41+00:00 2026-06-17T19:53:41+00:00

Let’s imagine I have global application configuration return array( ‘languages’ => array( ‘allowed’ =>

  • 0

Let’s imagine I have global application configuration

return array(

'languages' => array(
    'allowed'   => array('de', 'en'),
),

);

And I have module configuration with the routes description. I need routes, based on global configuration, so I need to read global application config within the module to compose my routes according to languages->allowed values (constraints for the segment type route)

What is the best way to get global configuration values from the module configuration script? is it correct at all to manipulate data in configuration file instead of simple array return?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:53:42+00:00Added an answer on June 17, 2026 at 7:53 pm

    You should think a bit more ahead of your problem. You want to create a route structure based on your configuration. The configuration could come from everywhere: module config, local config and global config. It is therefore quite hard to base your module’s config on a global one.

    What you can do, is create the routes later. For example, you create in your module Foo the config like this:

    'routes_foo' => array(
      'bar' => array(
        'type'    => 'segment',
        'options' => array(
          'route' => ':locale/foo/bar',
          'constraints' => array(
            'locale' => '%LOCALE%',
          ),
        ),
      ),
    ),
    

    And in your module class:

    namespace Foo;
    
    class Module
    {
        public function onBootstrap($e)
        {
            $app = $e->getApplication();
            $sm  = $app->getServiceManager();
    
            $config  = $sm->get('config');
            $routes  = $config['routes_foo');
            $locales = $config['languages']['allowed'];
    
            $routes = $this->replace($routes, array(
                '%LOCALE%' => sprintf('(%s)', implode('|', $locales)
            );
    
            $router = $sm->get('router');
            $router->routeFromArray($routes);
        }
    
        public function replace($array, $variables)
        {
            foreach ($array as $key => $value) {
                if (is_array($value)) {
                    $array[$name] = $this->replace($value, $variables);
                }
    
                if (array_key_exists($value, $variables)) {
                    $array[$name] = $variables[$value];
                }
            }
    
            return $array;
        }
    }
    

    What happens is you grab the routes from your config (those are not automatically injected in the router). There you also load all languages from your global config. Then your “custom” routes have (at several places) a “magic” configuration key, which will be replaced by a regex constraint for the locales: (en|de). That parsed config is then injected into the router.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let I have an array like a <- seq(1, 100, 1) and I want
Let's say for a moment that I have the following module in python: class
Let me frame it this way.. Say I have an application server running on
Let's say, I have an application that access(read/write) the file system(files inside application), Active
Let's say I have 2 windows in my application, and two classes responsible for
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I don't have photoshop, but I want to make pattern files (.pat)
Let's say I have a method in java, which looks up a user in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.