本文整理汇总了PHP中AppBundle\Entity\Post::addMark方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::addMark方法的具体用法?PHP Post::addMark怎么用?PHP Post::addMark使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\Post
的用法示例。
在下文中一共展示了Post::addMark方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load(ObjectManager $manager)
{
$faker = Factory::create();
for ($i = 0; $i < 50; $i++) {
static $id = 1;
$post = new Post();
$post->setTitle($faker->sentence);
$post->setAuthorEmail('user_admin@blog.com');
$post->setImageName("images/post/foto{$id}.jpg");
$post->setContent($faker->realText($maxNbChars = 5000, $indexSize = 2));
$marks = array();
for ($q = 0; $q < rand(1, 10); $q++) {
$marks[] = rand(1, 5);
}
$post->setMarks($marks);
$post->addMark(5);
$manager->persist($post);
$this->addReference("{$id}", $post);
$id = $id + 1;
$rand = rand(3, 7);
for ($j = 0; $j < $rand; $j++) {
$comment = new Comment();
$comment->setAuthorEmail('user_user@blog.com');
$comment->setCreatedBy('user_user');
$comment->setContent($faker->realText($maxNbChars = 500, $indexSize = 2));
$comment->setPost($post);
$post->getComments()->add($comment);
$manager->persist($comment);
$manager->flush();
}
}
$manager->flush();
}
示例2: markNewAction
/**
* @Route("/mark/{postSlug}/new", name = "mark_new")
* @Method("POST")
* @ParamConverter("post", options={"mapping": {"postSlug": "slug"}})
*/
public function markNewAction(Post $post, Request $request)
{
$form = $this->createForm(MarkType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$mark = $form->getData();
$entityManager = $this->getDoctrine()->getManager();
$post->addMark($mark['mark']);
$entityManager->flush();
return $this->redirectToRoute('blog_post', array('slug' => $post->getSlug()));
}
return $this->render('blog/_mark_form.html.twig', array('post' => $post, 'form' => $form->createView()));
}