Skip to content

Instantly share code, notes, and snippets.

@ahonymous
Created December 9, 2016 21:01
Show Gist options
  • Save ahonymous/8a00a3822c114f1591d8b994a34786a1 to your computer and use it in GitHub Desktop.
Save ahonymous/8a00a3822c114f1591d8b994a34786a1 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Author;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$authors = $em->getRepository('AppBundle:Author')->findAll();
return $this->render('default/index.html.twig', ['authors' => $authors]);
}
/**
* @Route("/fill", name="fill")
*/
public function fillAction()
{
$em = $this->getDoctrine()->getManager();
$count = $em->getRepository(Author::class)->selectCountAuthors();
$count++;
$author = new Author();
$author->setFirstName('Author');
$author->setLastName('First' . $count);
$author->setUsername('a' . $count);
$author->setBirthday(new \DateTime());
$em->persist($author);
$em->flush();
return $this->redirectToRoute('homepage');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment