本文整理汇总了PHP中AppBundle\Entity\Post::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::setId方法的具体用法?PHP Post::setId怎么用?PHP Post::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\Post
的用法示例。
在下文中一共展示了Post::setId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updatePostAction
/**
* Update existing post from the submitted data or create a new post at a specific location.
*
* @ApiDoc(
* resource = true,
* input = "AppBundle\Entity\Post",
* statusCodes = {
* 201 = "Returned when a new resource is created",
* 204 = "Returned when successful",
* 400 = "Returned when the form has errors"
* }
* )
*
* @Put("/posts/{id}", requirements={"id" = "\d+"})
*
* @param Request $request
* @param int $id
*
* @return View
*/
public function updatePostAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$post = $em->getRepository('AppBundle:Post')->find($id);
if (null === $post) {
$post = new PostEntity();
$post->setId($id);
$em->persist($post);
$metadata = $em->getClassMetadata(get_class($post));
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
$statusCode = Response::HTTP_CREATED;
} else {
$statusCode = Response::HTTP_NO_CONTENT;
}
$form = $this->createForm(new PostRestType(), $post);
$form->submit($request);
if ($form->isValid()) {
$post->setSlug($this->get('slugger')->slugify($post->getTitle()));
$em->flush();
return $this->routeRedirectView('get_post', array('id' => $post->getId()), $statusCode);
}
$view = new View($form);
return $this->handleView($view);
}