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 8670559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:44:09+00:00 2026-06-12T18:44:09+00:00

I’m in the process of learning ZF2 and planning an application. I would like

  • 0

I’m in the process of learning ZF2 and planning an application.

I would like to have 1 application with several groups of modules. Each group of modules could contain up-to 20+ modules.

I won’t be able to guarantee a unique name for any of the modules for the whole app, but i can guarantee their uniqueness within their module group.

Ideally route requests to module groups using a Hosting router.

e.g.
http://admin.mysite.com/foo/ => ‘Admin/Foo/Index/Index’,

http://special.mysite.com/foo/ => ‘Special/Foo/Index/Index’

Idea #1

I was hoping to use a different module_path for each module group and namespacing the module path around the module group to determine uniqueness of the module’s class. But modules sent to the module_autoloader only seem to pay any attention to the first part of any strings passed.

e.g.

array('modules' => array(
 'Admin\Admin','Admin\Bob','Admin\Users'
));

This gets strange behaviour I don’t understand:

  • All three will point to the correct module controller but they load the view for Admin\Admin (which is first in the module list) instead of their own.
  • I.E. /users, loads Admin\Users\IndexController but with the view script Admin\Admin\view\admin\Index\index.phtml

I’ve managed to fix this with some small alterations to the templateInjecter but it seems messy.

Idea #2

Just prefix module names to their subdirectory e.g.

namespace AdminAdmin\Controller,
class  IndexController {}

Thoughts

  • namespaces would be preferred to class prefixes
  • we’re trying to automate as much of this as possible instead of using hardcoded routes for each module
  • it could make sense to use multiple applications that share a module for authentication via a common cookie host/memcache and db, etc…
  • route each module to a certain subdomain using the hosting type routes inside a treeRouteStack of the modules controllers etc…

Question:

  • Is their a best practice for this situation or similar and why?
  • 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-12T18:44:11+00:00Added an answer on June 12, 2026 at 6:44 pm

    My interpretation of your question is that you’re really asking two questions:

    (1) Namespacing modules

    This is possible natively with ZF2. Modules in ZF2 are basically just PHP namespaces, so a module named Foo\Bar is perfectly acceptable, and by default the module loader will look for it’s module class in module/Foo/Bar then vendor/Foo/Bar.

    For example, if you wanted to create a module Anvil and under the namespace Acme, you would create directory module/Acme/Anvil, and inside it create a Module.php file:

    <?php
    namespace Acme\Anvil;
    
    class Module
    {
        /* module class code goes here */
    }
    

    In your application’s config/application.config.php you would add Acme\Anvil to the modules key:

    return array(
        'modules' => array(
            'Application',
            'Acme\Anvil',
        ),
        // Remaining bits of config array are unchanged
    );
    

    (2) Dynamically-loading modules

    One approach you could take would be to modify your site’s bootstrap index.php to modify the configuration on-the-fly based on the hostname. For example, using ZendSkeletonApplication you would set up your application.config.php file like so:

    <?php
    return array(
        'modules' => array(
            'Application',
            // Other modules common to all sites go here
        ),
        'sites' => array(
            'site-one.mydomain.com' => array(
                'modules' => array(
                    'ModuleOne',
                    'ModuleTwo',
                ),
            ),
            'site-two.mydomain.com' => array(
                'modules' => array(
                    'ModuleThree',
                ),
            ),
        ),
        // Remaining bits of config array are unchanged
    );
    

    To make this work we make a slight modification to public/index.php to intercept the configuration array loaded from config/application.config.php and reconfigure the modules key:

    // Pick host out of request
    $hostname = $_SERVER['HTTP_HOST'];
    
    // Load application configuration
    $applicationConfig = require 'config/application.config.php';
    
    // Merge site-specific modules into loaded modules array
    $applicationConfig['modules'] = array_merge(
        $applicationConfig['modules'],
        $applicationConfig['sites'][$hostname]['modules']
    );
    
    // Run the application!
    Zend\Mvc\Application::init($applicationConfig)->run();
    

    This approach provides an easy way to change which modules are loaded for a particular hostname, but can easily be extended to allow site-specific configuration file autoloading and site-specific module directories as well.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
This could be a duplicate question, but I have no idea what search terms
I would like to count the length of a string with PHP. The string
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.