Php 动态设置FOS UserBundle登录页面的样式

Php 动态设置FOS UserBundle登录页面的样式,php,symfony,fosuserbundle,Php,Symfony,Fosuserbundle,我对Symfony 2比较陌生,但我有一个网站,有许多不同的子域和用户区域,我希望我的登录页面样式不同,但目前不是这样。我正在使用Symfony 2和FOS用户包,目前在security.yml中使用1个防火墙时,一切都正常工作。我希望根据文档覆盖FOS用户包布局,但我希望能够根据请求的来源对该页面进行不同的样式设置,例如: microsite1.mainsite.com/user获得样式A microsite1.mainsite.com/admin获取样式B microsite2.mainsi

我对Symfony 2比较陌生,但我有一个网站,有许多不同的子域和用户区域,我希望我的登录页面样式不同,但目前不是这样。我正在使用Symfony 2和FOS用户包,目前在security.yml中使用1个防火墙时,一切都正常工作。我希望根据文档覆盖FOS用户包布局,但我希望能够根据请求的来源对该页面进行不同的样式设置,例如: microsite1.mainsite.com/user获得样式A microsite1.mainsite.com/admin获取样式B microsite2.mainsite.come/user获取样式C

我已经考虑了一些选择,我正在寻找其他的意见。我考虑的第一个选项是覆盖/扩展FOS用户包中的控制器,以便识别推荐人并呈现不同的细枝模板。另一个选择是对不同的路由使用不同的防火墙,但我们确实希望能够让不同微站点的用户跨所有站点进行身份验证,因此最好使用一个防火墙。是否有其他解决方案,或者是否有一种方法比另一种方法更适合解决这个相对较小的问题?

您可以覆盖
SecurityController的方法。以下是您如何做到这一点:

namespace Acme\UserBundle\Controller;
使用FOS\UserBundle\Controller\SecurityController作为BaseController;
使用Symfony\Component\DependencyInjection\ContainerWare;
使用Symfony\Component\Security\Core\SecurityContext;
使用Symfony\Component\HttpFoundation\Request;
类SecurityController扩展BaseController
{
/**
*覆盖FOS默认方法,以便我们可以选择模板
*/
受保护的函数renderLogin(数组$data)
{
$template=$this->getTemplate();
返回$this->container->get('templating')->renderResponse($template,$data);
}
/**
*获取子域并返回正确的模板
*/
公共函数getTemplate(){
$subdomain=$this->container->get('request')->getHost();
如果($subdomain==“microsite1.mainsite.com”){
$template=sprintf('AcmeUserBundle:Security:loginMicrosite1.html.%s',$this->container->getParameter('fos_user.template.engine');
}
elseif($subdomain==“microsite2.mainsite.com”){
$template=sprintf('AcmeUserBundle:Security:loginMicrosite2.html.%s',$this->container->getParameter('fos_user.template.engine');
}
//喋喋不休
//在这里根据您的需要进行定制。
返回$template;
}
您可以覆盖
SecurityController
的方法

namespace Acme\UserBundle\Controller;
使用FOS\UserBundle\Controller\SecurityController作为BaseController;
使用Symfony\Component\DependencyInjection\ContainerWare;
使用Symfony\Component\Security\Core\SecurityContext;
使用Symfony\Component\HttpFoundation\Request;
类SecurityController扩展BaseController
{
/**
*覆盖FOS默认方法,以便我们可以选择模板
*/
受保护的函数renderLogin(数组$data)
{
$template=$this->getTemplate();
返回$this->container->get('templating')->renderResponse($template,$data);
}
/**
*获取子域并返回正确的模板
*/
公共函数getTemplate(){
$subdomain=$this->container->get('request')->getHost();
如果($subdomain==“microsite1.mainsite.com”){
$template=sprintf('AcmeUserBundle:Security:loginMicrosite1.html.%s',$this->container->getParameter('fos_user.template.engine');
}
elseif($subdomain==“microsite2.mainsite.com”){
$template=sprintf('AcmeUserBundle:Security:loginMicrosite2.html.%s',$this->container->getParameter('fos_user.template.engine');
}
//喋喋不休
//在这里根据您的需要进行定制。
返回$template;
}