コード例 #1
0
ファイル: commentDAO.php プロジェクト: TAIBIHT/MyMovies
 /**
  * Creates an Comment object based on a DB row.
  *
  * @param array $row The DB row containing Comment data.
  * @return \MyMovies\Domain\Comment
  */
 protected function buildDomainObject($row)
 {
     $comment = new Comment();
     $comment->setId($row['com_id']);
     $comment->setContent($row['com_content']);
     if (array_key_exists('Cat_id', $row)) {
         // Find and set the associated article
         $articleId = $row['Cat_id'];
         $article = $this->articleDAO->find($articleId);
         $comment->setArticle($article);
     }
     return $comment;
 }
コード例 #2
0
ファイル: routes.php プロジェクト: TAIBIHT/MyMovies
<?php

use Symfony\Component\HttpFoundation\Request;
use MyMovies\Domain\Comment;
use MyMovies\Form\Type\CommentType;
// Home page
$app->get('/', function () use($app) {
    $articles = $app['dao.article']->findAll();
    return $app['twig']->render('index.html.twig', array('articles' => $articles));
})->bind('home');
// Article details with comments
$app->match('/article/{id}', function ($id, Request $request) use($app) {
    $article = $app['dao.article']->find($id);
    $commentFormView = null;
    if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) {
        // A user is fully authenticated : he can add comments
        $comment = new Comment();
        $comment->setArticle($article);
        $user = $app['user'];
        $comment->setAuthor($user);
        $commentForm = $app['form.factory']->create(new CommentType(), $comment);
        $commentForm->handleRequest($request);
        if ($commentForm->isSubmitted() && $commentForm->isValid()) {
            $app['dao.comment']->save($comment);
            $app['session']->getFlashBag()->add('success', 'Your comment was succesfully added.');
        }
        $commentFormView = $commentForm->createView();
    }
    $comments = $app['dao.comment']->findAllByArticle($id);
    return $app['twig']->render('article.html.twig', array('article' => $article, 'comments' => $comments, 'commentForm' => $commentFormView));
})->bind('article');