3

FOSUserBundle profile controller

 use Symfony\Component\DependencyInjection\ContainerAware;
 class ProfileController extends ContainerAware

some functions ok ... but when i try then creat form

$form = $this->createForm

This error appear: Call to undefined method ProfileController::createForm()

BUT when i change it to this:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class ProfileController extends Controller

The form is rendered... so ... i dont know how can i add this controller to my class and dont remove the ContainerAware ? :/

//

MY solution ?

instead of containeraware i use

use Symfony\Component\DependencyInjection\ContainerAwareInterface;

And then

class ProfileController extends Controller implements ContainerAwareInterface

But i dont know i cant see a different i am noob now so... is it good solution or i will broke something?

3 Answers 3

6

To answer your original question,

Replace:

$form = $this->createForm

With:

$form = $this->container->get('form.factory')->create($type, $data, $options);

The createForm method is just a convenience method defined in Symfony\Bundle\FrameworkBundle\Controller\Controller. For various reasons, 3rd party libraries tend not to extend the Controller class. Hence createForm is not available.

The real question is: why are you trying to extend the Profile controller? In most cases it is not necessary. It's better to do your customization by listening to events. That of course assumes you are using the development version of FOSUserBundle.

Sign up to request clarification or add additional context in comments.

Comments

2

Controller is already ContainerAware - from Controller declaration:

class Controller extends ContainerAware

4 Comments

Than why this error? Call to undefined method ProfileController::createForm()
You get error with decalaration class ProfileController extends Controller?
no, i get your sentence wrong... you meaned when i extends controller i dont have to implement containeraware?
Yes, that exactly what I meant. It's basics of inheritance.
2

Have a look at this blog Symfony2: Moving Away From the Base Controller by Richard Miller

1 Comment

Note that link-only answers are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.