Loading Modules Dynamically in Zend Framework 2

前端 未结 2 727

I have asked this question yesterday as well, but this one includes code.

Issue

My application have multiple modules and 2 types of user accounts, Some mod

2条回答
  •  不思量自难忘°
    2020-12-11 10:35

    I think there is some fundamental mistake in what you are trying to do here: you are trying to load modules based on merged configuration, and therefore creating a cyclic dependency between modules and merged configuration.

    I would advise against this.

    Instead, if you have logic that defines which part of an application is to be loaded, put it in config/application.config.php, which is responsible for retrieving the list of modules.

    At this stage though, it is too early to depend on any service, as service definition depends on the merged configuration too.

    Another thing to clarify is that you are trying to take these decisions depending on whether the authenticated user (request information, rather than environment information) matches a certain criteria, and then modifying the entire application based on that.

    Don't do that: instead, move the decision into the component that is to be enabled/disabled conditionally, by putting a guard in front of it.

提交回复
热议问题