📜  设置所有者 symfony - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:04.945000             🧑  作者: Mango

代码示例1
use AppBundle\Entity\Post; //at top of controller

$em = $this->getDoctrine()->getManager();
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$post = new Post();
$em->persist( $post );
$post->setOwner( $user );
// set other fields in your post entity
$em->flush();