0

I'm just started learning Symfony2. I have problem with using interface in controller. I've created very simple interface, then implemented it in controller and now Symfony debugger shout that my method is incompatible with interface. Below is my code.

Webrama\UserBundle\Controller:

namespace Webrama\UserBundle\Controller;

use Webrama\UserBundle\Model\InitializableControllerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller implements InitializableControllerInterface
{
    public function initialize(Request $request,
                               SecurityContextInterface $security_context,
                               FilterControllerEvent $event)
    {

    }
}

And the interface:

namespace Webrama\UserBundle\Model {

    interface InitializableControllerInterface
    {
        public function initialize(Request $request,
                                   SecurityContextInterface $security_context,
                                   FilterControllerEvent $event);
    }
}

I've simply copied method from interface, added a body to it and I can't see any problem here. Of course there is at least one. Any ideas?

1 Answer 1

3

Try adding this to your controller and your interface:

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
Sign up to request clarification or add additional context in comments.

4 Comments

Stupid. I don't understand why is that but it worked... Look's like i have to read some symfony tut.
+1 To elaborate on the correct answer; The interface's argument type hints are assumed to be within the same namespace (Webrama\UserBundle\Model) as you have not explicitly defined them with the use statement.
This has nothing to do with Symfony. It is just PHP OOP related.
no absolutly not :) I was just referring to "Look's like i have to read some symfony tut."

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.