我有一个symfony项目,有多个皮肤/模板,有他们自己的路线,谁有一个正确的设置的想法?
自定义RouteLoader执行任务--但是生成的路由正在缓存,据我所知,没有办法阻止路由缓存。
一些建议是:
有没有人?我不能真的参加多个项目,皮肤的数量将在20-30左右.
此设置的原因是因为它是以服务内容为目标的。服务,多个客户端使用项目作为平台,它们的设置决定使用哪些模板。
发布于 2015-11-06 15:46:36
听起来您想要根据主机名动态加载包吗?由于缓存的原因,Symfony 2不会发生。尤其是服务部门。
您最好的选择是为每个皮肤设置一个应用程序,然后执行一些url majic来执行所需的app.php文件。显然,既然你已经为每个皮肤定义了一个捆绑,那么就会有一个有限的数目,所以拥有多个应用程序应该不是很多,也不是什么负担。
您可能能够解决模板问题。您仍然需要加载所有的皮肤包,但是您可以使用模板名称或路径,并且可能会得到一些有用的东西。
但是服务呢?除非您开始附加主机名来服务id,否则我看不到任何工作。
发布于 2015-11-06 16:46:14
我认为可以通过在内核请求上添加监听器来动态加载twig模板,这取决于用户的情况。
我可以给你一段代码,希望它能帮到你:
/**
* On Kernel Request triggers the request to get the user config
* then adds TWIG paths depending on user TemplateName
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
//$userConfig = Retrieve your user config
if (null === $userConfig->getTemplateConfig()->getTemplate()->getName())
{
throw new TemplateConfigNotFoundException(sprintf("Could not find TemplateConfig for %s", $userConfig->getName()));
}
$template = $userConfig->getTemplateConfig()->getTemplate()->getName();
$path = sprintf('%s/../../%s/Resources/views', __DIR__, ucfirst($template));
if (!is_dir($path)) {
throw new TemplateNotFoundException(sprintf("Could not find template %s", $template));
}
$this->loader->prependPath($path);
$this->loader->addPath(sprintf('%s/../Resources/views/Default', __DIR__));
}在侦听器构造函数中将$this->加载器定义为\Twig_Loader_Filesystem。
希望它能给你一个线索
发布于 2015-11-06 15:41:24
Symfony2已经支持主机感知的开箱即用路由,如下所示:
website_customer_1:
path: /
host: customer1.example.com
defaults: { _controller: Customer1Bundle:Main:startPage, theme: template1 }
website_customer_2:
path: /
host: customer2.example.com
defaults: { _controller: Customer1Bundle:Main:startPage, theme: template2 }https://stackoverflow.com/questions/33569677
复制相似问题