我试图按照本教程覆盖 fos 用户包的默认控制器 [覆盖默认 FOSUserBundle 控制器][1]
我可以更改控制器,但是当我尝试提交按钮时它不起作用:
<?php
// src/AppBundle/Controller/RegistrationController.php
namespace AppBundleController;
use SymfonyComponentHttpFoundationRedirectResponse;
use FOSUserBundleControllerRegistrationController as BaseController;
use SymfonyComponentHttpFoundationRequest;
class RegistrationController extends BaseController
{
public function registerAction(Request $request)
{
/** @var $formFactory FactoryInterface */
$formFactory = $this->get('fos_user.registration.form.factory');
/** @var $userManager UserManagerInterface */
$userManager = $this->get('fos_user.user_manager');
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');
$user = $userManager->createUser();
$user->setEnabled(true);
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
var_dump('prova');
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$form = $this->createForm(RegistrationType::class, $user, [
'method' => 'POST',
]);
//$form = $formFactory->createForm();
//$form->setData($user);
$form->handleRequest($request);
if ($form->isSubmitted()) {
var_dump($form);
if ($form->isValid()) {
var_dump($form);
}
}
return $this->render('@FOSUser/Registration/register.html.twig', array(
'form' => $form->createView(),
));
}
}
提交工作前的var_dump,但里面的var_dump
if ($form->isSubmitted()) {
if ($form->isValid()) {
不工作.我相信提交逻辑在另一个代码中,但我不明白如何更改它。
我不明白这怎么可能。请帮帮我 ?
你没有为你的表单设置 formType,所以他没有什么可处理的。
这里有一个简单的例子:
$form = $this->createForm(YourFormType::class, $user, [
'method' => 'POST',
]);
祝你好运 ! :)