Created
December 9, 2016 21:01
-
-
Save ahonymous/8a00a3822c114f1591d8b994a34786a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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