我们的Symfony应用程序目前是一个应用程序,很快就需要能够将多个站点指向同一个Symfony核心,并根据当前所在的站点具有略微不同的功能.
举个例子,我们可能会在一个网站上展示横幅而不是另一个网站.另一个示例是将在不同站点上启用/禁用的付款选项.或者另一个是不同网站上表单上的不同字段.
有没有人有过以这种方式构建Symfony应用程序的经验?
如果您想为您的应用程序“主题化”,您可以使用 LiipThemeBundle ,它确实效果很好。对于功能激活/停用,您还可以使用FeatureToggleBundle捆绑包(最近很安静)。
您还可以实现像这样的基本助手:
/**
* Check if a feature is activated.
*
* @param string $feature Name of the feature
*
* @throws AccessDeniedHttpException
*/
protected function checkFeature($feature)
{
$features = $this->container->getParameter('app.features')
if (!$features[$feature]) {
throw new AccessDeniedHttpException();
}
}
...
$this->checkFeature('contact_form');
Run Code Online (Sandbox Code Playgroud)
通过这种配置:
app.features:
contact_form: false
Run Code Online (Sandbox Code Playgroud)