2

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 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

the problem is that I need develop a modules manager , with the option to install or not one or more modules in my dashboard, like the extensions manager of wordpress, is there another way to do this?
just the way i pointed out or like in magento where the module manager is a full indipendent site besides the normal application. where one application controlls the extensions off the other application. like composer.
Interesting, could you explain me better?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.