Reputation: 2003
I'm using FOSUserbunble, how can access the user object from another controller/form in another bunble? for example I have a BlogBundle and when I create a new post I need to save the userId in the post table. for the form I'm using buildForm extending AbstractType.
thanks
Upvotes: 0
Views: 297
Reputation: 726
You can do it via SecurityContext.
let's a example ..
namespace YourPackage\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\UserBundle\Model\UserInterface;
class YourController extends Controller{
/**
* Fetch a user object.
*
* @Route("/yourRoute", name="your_route")
* @Method()
* @Template()
*/
public function yourAction(Request $request)
{
$user = $this->container->get('security.context')->getToken()->getUser();
return $this->redirect($this->generateUrl('your_route'));
}}
Upvotes: 0