/** * Delete a blog entry. * * @Route("/delete/{id}") * @Methods({"GET"}) * * @param Post $post * * @throws createNotFoundException If the Post id doesn't match * * @return RedirectResponse */ public function deleteAction(Post $post) { if (!$post) { throw $this->createNotFoundException('Unable to find Blog post.'); } $manager = $this->getDoctrine()->getManager(); $post->setStatus('delete'); $manager->flush(); return $this->redirect($this->generateUrl('thijs_blog_admin_blog_index', array('status' => 'deleted')), 301); }
public function load(ObjectManager $manager) { $i = 1; $faker = \Faker\Factory::create(); while ($i <= 100) { $post = new Post(); $post->setTitle($faker->sentence(4)); $post->setLead($faker->text($maxNbChars = 10)); $post->setBody($faker->text($maxNbChars = 400)); $post->setImage($faker->word($maxNbChars = 14) . '.jpg'); $post->setStatus($post::PUBLISHED); $fakerPublishDate = $faker->dateTimeBetween('-1 years', '+1 month'); $post->setPublishedAt($fakerPublishDate); $post->setCreatedAt($post->getPublishedAt()); $post->setUpdatedAt($post->getPublishedAt()); $rand = rand(1, 10); $post->setAuthor($this->getReference('user-' . $rand)); $rand = rand(1, 6); $post->setCategory($this->getReference('category-' . $rand)); $post->setTags('symfony2, php'); $manager->persist($post); $this->addReference('post-' . $i, $post); ++$i; } $manager->flush(); }