예제 #1
0
 public function indexAction($title)
 {
     $viewHandler = $this->container->get('my_view');
     $view = new View();
     $view->setTemplate(new TemplateReference('LiipHelloBundle', 'Hello', 'index'));
     try {
         $documentManager = $this->container->get('doctrine_phpcr')->getManager();
         $repo = $documentManager->getRepository('Liip\\HelloBundle\\Document\\Article');
         $article = $repo->find($repo->appendRootNodePath($title));
     } catch (\Exception $e) {
         $view->setData(array('name' => 'Did you run "app/console doctrine:phpcr:init:dbal" yet? (Exception: ' . $e->getMessage()));
         return $viewHandler->handle($view);
     }
     if ($article) {
         $article->setBody((string) ($article->getBody() + 1));
     } else {
         $article = new Article();
         $article->setTitle($title);
         $article->setBody('1');
         $documentManager->persist($article);
     }
     $documentManager->flush();
     $view->setData(array('name' => $title . ' ' . $article->getBody()));
     return $viewHandler->handle($view);
 }
예제 #2
0
 private function createArticle($article)
 {
     $text = $article;
     $article = new Article();
     $article->setPath('/' . $text);
     $article->setTitle($text);
     $article->setBody("This article is about '{$text}' and its really great and all");
     return $article;
 }
예제 #3
0
 public function validationFailureAction()
 {
     $validator = $this->validator;
     $article = new Article();
     //$article->setPath('/foo');
     $article->setTitle('The path was set');
     $article->setBody('Disable the setPath() call to get a validation error example');
     $view = new View();
     $errors = $validator->validate($article);
     if (count($errors)) {
         $view->setStatusCode(400);
         $view->setData($errors);
     } else {
         $view->setData($article);
     }
     return $this->viewHandler->handle($view);
 }