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

  • Home
  • SEARCH
  • 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 6338931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:32:44+00:00 2026-05-24T19:32:44+00:00

I have build a CMS using Zend Framework (1.11). In the application I have

  • 0

I have build a CMS using Zend Framework (1.11). In the application I have two modules, one called ‘cms’ which contains all the CMS logic and an other ‘web’ which enables a user to build their own website around the CMS. This involves adding controllers/views/models etc all in that module.

The application allows you to serve multiple instances of the app with their own themes. These instances are identified by the hostname. During preDispatch(), a database lookup is done on the hostname. Based on the database field ‘theme’ the app then loads the required css files and calls Zend_Layout::setLayout() to change the layout file for that specific instance.

I want to extend this functionality to also allow the user to run different web modules based on the ‘theme’ db field. However, this is where I am stuck. As it is now, the web module serves the content for all the instances of the application.

I need the application to switch to a different web module based on the ‘theme’ database value (so indirectly the hostname). Any ideas?

  • 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-05-24T19:32:45+00:00Added an answer on May 24, 2026 at 7:32 pm

    Well, in my opinion,

    You should write a front controller plugin for the web module, and do it so, that when you need another plugin, you can do so easily.

    The front controller plugin should look something like this:

    class My_Controller_Plugin_Web extends My_Controller_Plugin_Abstract implements My_Controller_Plugin_Interface
    { 
        public function init()
        {
            // If user is not logged in - send him to login page
            if(!Zend_Auth::getInstance()->hasIdentity()) {
    
                // Do something
                return false;
    
            } else {
    
                // You then take the domain name
                $domainName = $this->_request->getParam( 'domainName', null );
    
                // Retrieve the module name from the database
                $moduleName = Module_fetcher::getModuleName( $domainName );
    
                // And set the module name of the request
                $this->_request->setModuleName( $moduleName );
    
                if(!$this->_request->isDispatched()) {
    
                    // Good place to alter the route of the request further 
                    // the way you want, if you want 
    
                    $this->_request->setControllerName( $someController );
                    $this->_request->setActionName( $someAction );
                    $this->setLayout( $someLayout );
    
                }
            }   
        }
    
    /**
     * Set up layout
     */
        public function setLayout( $layout )
        {
            $layout = Zend_Layout::getMvcInstance();
            $layout->setLayout( $layout );
        }   
    }
    

    And the My_Controller_Plugin_Abstract, which is not an actual abstract and which your controller plugin extends,looks like this:

    class My_Controller_Plugin_Abstract
    {
        protected $_request;
    
        public function __construct($request)
        {
            $this->setRequest($request);
            $this->init();
        }
    
        private function setRequest($request)
        {
            $this->_request = $request;
        }
    }
    

    And in the end the front controller plugin itself, which decides which one of the specific front controller plugins you should execute.

    require_once 'Zend/Controller/Plugin/Abstract.php';
    require_once 'Zend/Locale.php';
    require_once 'Zend/Translate.php';
    
    class My_Controller_Plugin extends Zend_Controller_Plugin_Abstract
    {
    
    /**
     * before dispatch set up module/controller/action
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function routeShutdown(Zend_Controller_Request_Abstract $request)
    {
        // Make sure you get something
        if(is_null($this->_request->getModuleName())) $this->_request->setModuleName('web');
    
        // You should use zend - to camelCase convertor when doing things like this
        $zendFilter = new Zend_Filter_Word_SeparatorToCamelCase('-');
        $pluginClass = 'My_Controller_Plugin_' 
                       . $zendFilter->filter($this->_request->getModuleName());
    
        // Check if it exists
        if(!class_exists($pluginClass)) { 
            throw new Exception('The front controller plugin class "' 
                                 . $pluginClass. ' does not exist');
        }
    
        Check if it is written correctly
        if(!in_array('My_Controller_Plugin_Interface', class_implements($pluginClass))) {   
            throw new Exception('The front controller plugin class "' 
                                 . $pluginClass.'" must implement My_Controller_Plugin_Interface'); 
        }
    
        // If all is well instantiate it , and you will call the construct of the 
        // quasi - abstract , which will then call the init method of your 
        // My_Plugin_Controller_Web :)
        $specificController = new $pluginClass($this->_request); 
    }
    

    }

    If you have never done this, now is the time. 🙂

    Also, to register your front controller plugin with the application, you should edit the frontController entry in your app configuration. I will give you a json example, i’m sure you can translate it to ini / xml / yaml if you need…

    "frontController": {
        "moduleDirectory": "APPLICATION_PATH/modules",
        "defaultModule": "web",
        "modules[]": "",
        "layout": "layout",
        "layoutPath": "APPLICATION_PATH/layouts/scripts",
        // This is the part where you register it! 
        "plugins": {
            "plugin": "My_Controller_Plugin"
         } 
    

    This might be a tad confusing, feel free to ask for a more detailed explanation if you need it.

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

Sidebar

Related Questions

I would like to build a cms with php using zend framework. I have
I have an asp.net application which is purely build using C#, CSS, Javascript. Now
We have to build Strings all the time for log output and so on.
I have to build a GUI application on Windows Mobile, and would like it
I'm going to have to build a custom control for a WinForms application. But
I am thinking of learning a CMS. I am not sure which one will
I have a login.jsp page which contains a login form. Once logged in the
The problem we have are as follows: We are using ANT to build our
We have a relatively large web application (>200 pages) to which we need to
We have a build process that needs to decrypt a password which it then

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.