Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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;
share|improve this answer
 
Stupid. I don't understand why is that but it worked... Look's like i have to read some symfony tut. –  PAM 19 hours ago
1  
+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. –  AlexP 19 hours ago
 
This has nothing to do with Symfony. It is just PHP OOP related. –  Markus Kottländer 19 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.