I've got a standard FOS user that's got a ManyToOne entity relationship with a blog entity.
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="blog")
* @ORM\JoinColumn(name="user", referencedColumnName="id")
*/
private $user;
I've used the app/console generate:doctrine:crud command to generate a basic crud system.
When I create a new blog entity I want to insert the logged in user that performed the action. By default Symfony generates CRUD code that allows the user to select which user is connected to the entity.
$builder
->add('name')
->add('address')
->add('facebook')
->add('twitter')
->add('user')
;
In the controller I can access the logged in user using security.context:
$user = $this->get('security.context')->getToken()->getUser();
Whats the best course of action to change this?