当我尝试通过遵循Symfony文档覆盖registrationController的控制器时,我正在使用Fosuserbundle来管理我的项目{ SF::3.4.8 }中的成员
<?php
namespace TestUserBundle;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOSUserBundle\Controller\RegistrationController as BaseController;
class RegistrationController extends BaseController {
public function registerAction(Request $request)
{
die("Hello");
}
}
但系统忽略该控制器仍然使用原始控制器,所以如果有任何方法来覆盖我的控制器
1 回答
首先,覆盖控制器可能不是最好的处理方式 . 你应该考虑挂钩到控制器 . 以下是相关文档:https://symfony.com/doc/master/bundles/FOSUserBundle/controller_events.html
然后,如果您仍想覆盖控制器,则应该在依赖注入中执行操作 . 控制器的服务名称是
fos_user.registration.controller
.要替换服务,您只需使用:
您也可以在CompilerPass中覆盖它 . 这可能是最适合您的解决方案,因为您在另一个包中执行此操作 .
以下是它的外观:
别忘了register it inside your bundle: