From 44c555bcb71f9f56cd0e9a0b33c454b7af238e84 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Sun, 1 Jul 2012 20:29:59 +0200 Subject: [PATCH] Fixed main page controller function Signed-off-by: Gergely POLONKAI (W00d5t0ck) --- .../Controller/DefaultController.php | 12 +++++++++ src/KekRozsak/FrontBundle/Entity/Article.php | 27 +++++++++++++++++++ .../Resources/config/doctrine/Article.orm.yml | 4 +++ .../views/Default/front_template.html.twig | 12 ++++----- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/KekRozsak/FrontBundle/Controller/DefaultController.php b/src/KekRozsak/FrontBundle/Controller/DefaultController.php index d4011cd..dbfc1db 100644 --- a/src/KekRozsak/FrontBundle/Controller/DefaultController.php +++ b/src/KekRozsak/FrontBundle/Controller/DefaultController.php @@ -6,10 +6,22 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { + public function homepageAction() + { + $mainPageArticle = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBy(array('main_page' => 1), true, array('created_at', 'DESC'), 1); + if (!$mainPageArticle) + throw $this->createNotFoundException('A keresett cikk nem létezik!'); + + return $this->forward('KekRozsakFrontBundle:Default:article', array('articleSlug' => $mainPageArticle->getSlug())); + } + public function articleAction($articleSlug) { $article = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBySlug($articleSlug); + if (!$article) + throw $this->createNotFoundException('A keresett cikk nem létezik!'); + return $this->render('KekRozsakFrontBundle:Default:article.html.twig', array( 'article' => $article )); diff --git a/src/KekRozsak/FrontBundle/Entity/Article.php b/src/KekRozsak/FrontBundle/Entity/Article.php index 3d0731f..3277ef1 100644 --- a/src/KekRozsak/FrontBundle/Entity/Article.php +++ b/src/KekRozsak/FrontBundle/Entity/Article.php @@ -267,4 +267,31 @@ class Article { return $this->updated_by; } + /** + * @var boolean $main_page + */ + private $main_page; + + + /** + * Set main_page + * + * @param boolean $mainPage + * @return Article + */ + public function setMainPage($mainPage) + { + $this->main_page = $mainPage; + return $this; + } + + /** + * Get main_page + * + * @return boolean + */ + public function getMainPage() + { + return $this->main_page; + } } \ No newline at end of file diff --git a/src/KekRozsak/FrontBundle/Resources/config/doctrine/Article.orm.yml b/src/KekRozsak/FrontBundle/Resources/config/doctrine/Article.orm.yml index e92406d..ef09ac6 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/doctrine/Article.orm.yml +++ b/src/KekRozsak/FrontBundle/Resources/config/doctrine/Article.orm.yml @@ -29,6 +29,10 @@ KekRozsak\FrontBundle\Entity\Article: update_reason: type: text nullable: true + main_page: + type: boolean + nullable: true + default: false manyToOne: created_by: targetEntity: User diff --git a/src/KekRozsak/FrontBundle/Resources/views/Default/front_template.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Default/front_template.html.twig index e0e8e88..c929261 100644 --- a/src/KekRozsak/FrontBundle/Resources/views/Default/front_template.html.twig +++ b/src/KekRozsak/FrontBundle/Resources/views/Default/front_template.html.twig @@ -8,18 +8,18 @@