Definitely possible, although the details depend on what you're doing in each controller action. The easiest way would be to have:
class PublicController extends \Symfony\Bundle\FrameworkBundle\Controller\Controller
{
public function indexAction()
{
if ($this->getUser() !== null) {
return $this->forward('BundleName:PrivateController:index');
}
// do public controller details
}
}
So by default everyone is sent to PublicController:indexAction
which does a check to see if there is a logged in user (using the getUser
method from Symfony's Controller class) and if there is, forward the request over to PrivateController:indexAction
. If not, then it just shows the public action as expected. You could invert this if you're expecting more logged in than logged out users as there will be a performance penalty for forwarding (as Symfony will create and dispatch a subrequest).
The longer answer is understanding what you're doing in each controller that requires them to be separate and whether you could combine the functionality into a service or otherwise re-architect them. Without knowing more about your specific problem domain, the above seems like the best way forward.