简体   繁体   English

Symfony2-捆绑包以外的东西

[英]Symfony2 - something other than bundle

I'm currenly working on the project where i need something orther than bundle. 我目前正在从事需要除捆绑以外的其他项目的工作。 Something i call "Module". 我称之为“模块”。 It should be different from the bundle in that when project is starting system doesn't know which "Modules" will be used and how they will be configured. 它与捆绑软件的区别在于,在项目启动时,系统不知道将使用哪个“模块”以及如何配置它们。

Also i'm going to use these modules similar to bundles 我也将使用与捆绑包类似的这些模块

$response = $this->forward('AcmeHelloModule:Hello:fancy');

OR 要么

$response = $this->forward('Acme/Hello:Hello:fancy');

Here HelloController->fancyAction(); 这里HelloController-> fancyAction(); would be executed. 将被执行。 And this controller described say in file /src/modules/Acme/Hello/Controller/HelloController.php 这个控制器在文件/src/modules/Acme/Hello/Controller/HelloController.php中描述了

So the question is how to implement this ? 那么问题是如何实现呢?

In AppKernel add the following method: 在AppKernel中添加以下方法:

public function getBundle($name, $first = true)
{
    if (substr($name, -6) == 'Module')) {
        return $this->getBundle('ModuleBundle')->getModule($name, $first);
    }

    return parent::getBundle($name, $first);
}

and all the logic runs in ModuleBundle. 并且所有逻辑都在ModuleBundle中运行。 But make sure the type of response is the same as Kernel->getBundle(); 但是请确保响应的类型与Kernel-> getBundle();相同。

a solution would be to implement a PluginBundle that can dynamicly install, load and run your so called modules. 一个解决方案是实现一个可以动态安装,加载和运行您所谓的模块的PluginBundle。

the PluginBundle would not contain specific plugin code at all, but the runtime environment for you modules/plugins. PluginBundle根本不包含特定的插件代码,而是模块/插件的运行时环境。 you may then save in the database which plugins/modules are enabled and load them dynamicly at runtime. 然后,您可以将启用了哪些插件/模块保存在数据库中,并在运行时动态加载它们。

with this sollution it should be possible to create a dynamic plugin mechanism as in wordpress. 通过这种解决方案,应该可以像在wordpress中那样创建动态插件机制。 modifying the AppKernel at runtime is not a good solution because you'd also have to clear the cache when en- disabeling bundles. 在运行时修改AppKernel并不是一个好的解决方案,因为在禁用捆绑软件时还必须清除缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM