我想通过扩展新的树枝布局来更改项目中注册表单的模板。但它并没有改变。它没有显示任何错误,但我仍然得到表单的原始视图。我做了我在文档中找到的所有内容,但它仍然没有改变,为什么?
1)我扩展了userBundle。
2)我创建了ApplicationSonataUserBundle并执行了此操作:
class ApplicationSonataUserBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function getParent()
{
return 'SonataUserBundle';
}
}
我制作了我的新控制器并覆盖了旧控制器(我只更改了渲染的布局):
<?php
namespace Application\Sonata\UserBundle\Controller;
use Sonata\UserBundle\Controller\RegistrationFOSUser1Controller as BaseController;
class Registration1Controller extends BaseController
{
public function registerAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
if ($user instanceof UserInterface) {
$this->container->get('session')->getFlashBag()->set('sonata_user_error', 'sonata_user_already_authenticated');
$url = $this->container->get('router')->generate('sonata_user_profile_show');
return new RedirectResponse($url);
}
$form = $this->container->get('sonata.user.registration.form');
$formHandler = $this->container->get('sonata.user.registration.form.handler');
$confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');
$process = $formHandler->process($confirmationEnabled);
if ($process) {
$user = $form->getData();
$authUser = false;
if ($confirmationEnabled) {
$this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
$url = $this->container->get('router')->generate('fos_user_registration_check_email');
} else {
$authUser = true;
$route = $this->container->get('session')->get('sonata_basket_delivery_redirect');
if (null !== $route) {
$this->container->get('session')->remove('sonata_basket_delivery_redirect');
$url = $this->container->get('router')->generate($route);
} else {
$url = $this->container->get('session')->get('sonata_user_redirect_url');
}
}
$this->setFlash('fos_user_success', 'registration.flash.user_created');
$response = new RedirectResponse($url);
if ($authUser) {
$this->authenticateUser($user, $response);
}
return $response;
}
$this->container->get('session')->set('sonata_user_redirect_url', $this->container->get('request')->headers->get('referer'));
return $this->container->get('templating')->renderResponse('MpShopBundle:Frontend:registration.html.'.$this->getEngine(), array(
'form' => $form->createView(),
));
}
}
3)我将new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
添加到AppKernel。
我错过了什么吗?可能是什么问题?
更新:
现在我收到此错误:Compile Error: Namespace declaration statement has to be the very first statement in the script
。但我的命名空间是第一个声明不是吗?