Strong Like Bull
Strong Like Bull

Reputation: 11307

How to access a controller in another bundle in Symfony?

I have a Symfony application that provides a REST interface. When a client requests a URL, the resource validates the username/password in the URL and then provides access. However the controller, that validates the URL, is in another bundle and is called validateCredentialsAction.

How do I call this validateCredentialsAction from another controller in another bundle?

Upvotes: 0

Views: 1278

Answers (1)

room13
room13

Reputation: 1922

You could define your authentication controller as a service according to http://symfony.com/doc/master/cookbook/controller/service.html, then inject it into the other controller.

However this could get problematic because a controller action should return a Response object and not a boolean indicating wether the authentication was successful.

So it would be better to refactore your code and extract the authentication part into a buisiness service that provides only authentication and no controller capabilities and then inject this service into both controllers.

Upvotes: 3

Related Questions