How Disable a specific module on Zend Framework 2 dynamically

1.2k views Asked by At

How to disable a specific module in ZF2 using a database I have a list of modules in the configuration file thinking that at some point in my application, read a table with the names of modules and disables them that are flaged as disabled in the database

in my case I am using Doctrine2 as my database

3

There are 3 answers

0
larry On BEST ANSWER

The lazy-loading module manager from Vincent Blanchon may be a solution to your problem. It allows to conditionnally enable or disable modules.

https://github.com/blanchonvincent/zf2-lazy-loading-module

0
Saurabh Chandra Patel On

I have better way to do this

just load only application module in application config file

in application.config.php

'modules' => array( 

    'DoctrineModule',
    'DoctrineORMModule', 
    'Application',

),

then write a method in application/module.php called

public function init(ModuleManager $moduleManager) {

        $moduleManager->loadModule('xyz'); // xyz module will be fetched from db here or depend on you logic.


    }

Now your module is loaded by your db.

3
ins0 On

the application.config.php is one of the first elements loaded by the zf2 bootstrapping and are passed to the ServiceManager wich loop all Modules (and load) listed in the application.config.php. At this point doctrine is not loaded (so you can't check if a module is "actived" in you'r database ) with a script running with zend framework.

when you check the public/index.php you are able to see the line where the bootstrapping begin

// Run the application!

Zend\Mvc\Application::init(require 'config/application.config.php')->run();

this is your point where you logic should be implement (establish a database connection, create a application config) and pass it to the init() method.

but this is not a good idea, because you need to specify a db connection, set db passwords etc. and "go your own way without zf2".

when you disable modules dynamicly i think you make something "wrong", because either you need a module or you don't - either a module is enabled in development environment and disabled in your live environment. simple as it