我想覆盖FOSUserBundle的RegistrationController
。我已经按照the documentation和可以得到的Symfony用我的控制器来代替,但我正在逐渐时,其registerAction
方法被调用此错误:FOSUserBundle的控制器覆盖中不存在的服务
You have requested a non-existent service "fos_user.registration.form"
我修改了DependencyInjection\Configuration
类以匹配原始之一,但服务别似乎被添加。 FOSUserBundle的文档没有提到这个问题,所以我不知道如何正确设置它。
这里是我的文件:
RegistrationController.php
namespace ACME\AuthBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
use Symfony\Component\HttpFoundation\Request;
class RegistrationController extends BaseController
{
public function registerAction(Request $request)
{
$form = $this->container->get('fos_user.registration.form'); // Source of error
...
}
}
的configuration.php
namespace ACME\AuthBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('fos_user');
$rootNode
->children()
->arrayNode('registration')
->addDefaultsIfNotSet()
->canBeUnset()
->children()
->arrayNode('confirmation')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->scalarNode('template')->defaultValue('FOSUserBundle:Registration:email.txt.twig')->end()
->arrayNode('from_email')
->canBeUnset()
->children()
->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
->scalarNode('sender_name')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('fos_user_registration')->end()
->scalarNode('name')->defaultValue('fos_user_registration_form')->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
->defaultValue(array('Registration', 'Default'))
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
您是否在应用程序/ AppKernel.php中激活了FOSUserBundle,并且该应用程序/控制台容器中提供了此服务:debug? –
是的,FOSUserBundle被激活。 'container:debug'中没有列出具体的'fos_user.registration.form',尽管有一些子服务,比如'fos_user.registration.form.factory'。试图使用它们,所以我如何添加一个我需要的? – Jukurrpa