Created
December 9, 2015 20:59
-
-
Save ahonymous/e20f6ce2a9e413bb671b to your computer and use it in GitHub Desktop.
This file contains 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\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Article | |
* | |
* @ORM\Table(name="article") | |
* @ORM\Entity(repositoryClass="AppBundle\Repository\ArticleRepository") | |
*/ | |
class Article | |
{ | |
/** | |
* @var int | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="title", type="string", length=255) | |
*/ | |
private $title; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="description", type="text") | |
*/ | |
private $description; | |
/** | |
* @var Author | |
* | |
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Author", inversedBy="articles") | |
*/ | |
private $author; | |
/** | |
* Get id | |
* | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* Set title | |
* | |
* @param string $title | |
* | |
* @return Article | |
*/ | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
return $this; | |
} | |
/** | |
* Get title | |
* | |
* @return string | |
*/ | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
/** | |
* Set description | |
* | |
* @param string $description | |
* | |
* @return Article | |
*/ | |
public function setDescription($description) | |
{ | |
$this->description = $description; | |
return $this; | |
} | |
/** | |
* Get description | |
* | |
* @return string | |
*/ | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
/** | |
* Set author | |
* | |
* @param \AppBundle\Entity\Author $author | |
* | |
* @return Article | |
*/ | |
public function setAuthor(\AppBundle\Entity\Author $author = null) | |
{ | |
$this->author = $author; | |
return $this; | |
} | |
/** | |
* Get author | |
* | |
* @return \AppBundle\Entity\Author | |
*/ | |
public function getAuthor() | |
{ | |
return $this->author; | |
} | |
} |
This file contains 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\Repository; | |
/** | |
* ArticleRepository | |
* | |
* This class was generated by the Doctrine ORM. Add your own custom | |
* repository methods below. | |
*/ | |
class ArticleRepository extends \Doctrine\ORM\EntityRepository | |
{ | |
public function getArticles() | |
{ | |
return $this->createQueryBuilder('a') | |
->join('a.author', 'au') | |
->getQuery() | |
->getResult(); | |
} | |
} |
This file contains 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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Symfony\Component\HttpFoundation\Request; | |
class DefaultController extends Controller | |
{ | |
/** | |
* @Route("/", name="homepage") | |
*/ | |
public function indexAction(Request $request) | |
{ | |
$articles = $this->getDoctrine()->getRepository('AppBundle:Article')->getArticles(); | |
dump($articles); | |
// replace this example code with whatever you need | |
return $this->render('default/index.html.twig', array( | |
'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment