3615_Internet
3615_Internet

Reputation: 125

Extending Controller - Nothing Happens

I'm trying to figure that problem for a long day.

I have Sonata User Bundle installed and I use it to manage users and profile edition and so on.

BUT, I a need to override Sonata Profile Controller.

If I understood correctly (I'm a perfect beginner in Symfony), I have to extend SonataUserBundle (which has been done using the easy extend bundle).

So, when I declare a new controller, nothing happens. Not even an error message.

Any ideas ?

Here are my files

[ BUNDLE EXTENSION FILE ]

   // ApplicationSonataUserBundle.php

    namespace Application\Sonata\UserBundle;

    use Symfony\Component\HttpKernel\Bundle\Bundle;

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

[ CONTROLLER FILE ]

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',
    ));
    }

}

Upvotes: 0

Views: 71

Answers (2)

3615_Internet
3615_Internet

Reputation: 125

Ok so I have found the answer by myself :)

I forgot to specify the classes I needed

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;

I cleared the cache and everything was ok !

Thanks all !

Upvotes: 1

Radoje Albijanic
Radoje Albijanic

Reputation: 43

You have die('toto'); as first line in the controller method, isn't that going to terminate all code below?

Upvotes: 1

Related Questions