扩展控制器 - 没有任何反应

Extending Controller - Nothing Happens

我花了一整天的时间来解决这个问题。

我安装了 Sonata User Bundle,我用它来管理用户和配置文件版本等。

但是,我需要覆盖 Sonata Profile Controller。

如果我理解正确(我是 Symfony 的完美初学者),我必须扩展 SonataUserBundle(已使用 easy extend bundle 完成)。

因此,当我声明一个新控制器时,没有任何反应。甚至没有错误消息。

有什么想法吗?

这是我的文件

[捆绑扩展文件]

   // ApplicationSonataUserBundle.php

    namespace Application\Sonata\UserBundle;

    use Symfony\Component\HttpKernel\Bundle\Bundle;

    class ApplicationSonataUserBundle extends Bundle
    {
        /**
         * {@inheritdoc}
         */
        public function getParent()
        {
            return 'SonataUserBundle';
        }
    }

[控制器文件]

namespace Application\Sonata\UserBundle\Controller;
use Sonata\UserBundle\Controller\ProfileFOSUser1Controller as BaseController;

class ProfileFOSUser1Controller extends BaseController {

    public function editProfileAction() {
    die('toto');
    $user = $this->getUser();
    if (!is_object($user) || !$user instanceof UserInterface) {
        throw new AccessDeniedException('This user does not have access to this section.');
    }

    $form = $this->get('sonata.user.profile.form');
    $formHandler = $this->get('sonata.user.profile.form.handler');

    $process = $formHandler->process($user);
    if ($process) {
        $this->setFlash('sonata_user_success', 'profile.flash.updated');

        return $this->redirect($this->generateUrl('sonata_user_profile_edit'));
    }

    return $this->render('SonataUserBundle:Profile:edit_profile.html.twig', array(
            'form' => $form->createView(),
            'breadcrumb_context' => 'user_profile',
    ));
    }

}

您在控制器方法中将 die('toto'); 作为第一行,这不会终止下面的所有代码吗?

好的,我自己找到了答案:)

我忘记指定 类 我需要的

use FOS\UserBundle\Model\UserInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Sonata\UserBundle\Controller\ProfileFOSUser1Controller as BaseController;

我清除了缓存,一切正常!

谢谢大家!