/** * Render js inclusion for create.js and dependencies and bootstrap code. * * THe hallo editor is bundled with create.js and available automatically. * To use aloha, you need to download the zip, as explained in step 8 of * the README. * * @param string $editor the name of the editor to load, currently hallo and aloha are supported */ public function includeJSFilesAction($editor = 'hallo') { if ($this->securityContext && false === $this->securityContext->isGranted($this->requiredRole)) { return new Response(''); } // We could inject a list of names to template mapping for this // to allow adding other editors without changing this bundle $view = new View(); switch ($editor) { case 'hallo': if ($this->coffee) { $view->setTemplate('SymfonyCmfCreateBundle::includecoffeefiles-hallo.html.twig'); } else { $view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-hallo.html.twig'); } break; case 'aloha': $view->setTemplate('SymfonyCmfCreateBundle::includejsfiles-aloha.html.twig'); break; default: throw new \InvalidArgumentException("Unknown editor '{$editor}' requested"); } $view->setData(array('cmfCreateStanbolUrl' => $this->stanbolUrl, 'cmfCreateImageUploadEnabled' => (bool) $this->imageClass)); return $this->viewHandler->handle($view); }
/** * @expectedException \InvalidArgumentException */ public function testSetTemplateTemplateFormat() { $view = new View(); $view->setTemplate('foo'); $this->assertEquals('foo', $view->getTemplate()); $view->setTemplate($template = new TemplateReference()); $this->assertEquals($template, $view->getTemplate()); $view->setTemplate(array()); }
/** * @Route("/") */ public function indexAction() { $view = new View(); $view->setFormat('html'); $view->setTemplate('TastdCoreBundle:Default:index.html.twig'); return $view; }
/** * @ApiDoc( * section="Admin/Users", * description="Display the creation form of the user", * input="AppBundle\Controller\Admin\Form\UserFormType", * output="AppBundle\Controller\Admin\AdminUserController", * ) */ public function newUserAction() { $user = new User(); $form = $this->getUserForm($user, 'post_user', 'POST'); $view = new View($form); $view->setTemplate('AppBundle:User:add.html.twig'); return $this->handleView($view); }
public function getView($msg, $code) { $data1 = new Response($msg, $code); $view = new View($data1); $view->setTemplate('AppBundle:message.html.twig'); $view->setTemplateVar('data'); return $view; }
protected function renderResponse($contentTemplate, $params) { if ($this->viewHandler) { $view = new View($params); $view->setTemplate($contentTemplate); return $this->viewHandler->handle($view); } return $this->templating->renderResponse($contentTemplate, $params); }
/** * @ApiDoc( * section="Claims", * description="Display the claimed requests of a user", * output="AppBundle\Controller\ClaimController", * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="The user's id"} * } * ) */ public function getClaimedByUserAction($id) { $rep = $this->getDoctrine()->getRepository('AppBundle:Claim'); $claims = $rep->findClaimedByUser($id); $view = new View($claims, 200); $view->setTemplate('AppBundle:Claim:claimed.html.twig'); $view->setTemplateVar('claimeds'); return $this->handleView($view); }
/** * alternatively use class="LiipHelloBundle:Article", but this has a bit more overhead * * @ParamConverter("article", class="Liip\HelloBundle\Document\Article") */ public function converterAction(Article $article = null) { $view = new View(); $view->setTemplate(new TemplateReference('LiipHelloBundle', 'Hello', 'index')); $name = $article ? 'found: ' . $article->getTitle() : 'No found'; $view->setData(array('name' => $name)); $viewHandler = $this->container->get('my_view'); return $viewHandler->handle($view); }
/** * @ApiDoc( * section="Categories", * description="Display the creation form of categories", * output="AppBundle\Controller\CategoryController", * parameters={ * {"name"="cat", "dataType"="string", "required"=true, "description"="Category's name"}, * } * ) */ public function getCategoryItemsAction($cat) { $rep = $this->getDoctrine()->getRepository('AppBundle:Category'); $category = $rep->findForItem($cat); $view = new View($category); $view->setTemplate('AppBundle:Category:items.html.twig'); $view->setTemplateVar('items'); //dump($view);die(); return $this->handleView($view); }
public function editContenidoAction($id) { $em = $this->getDoctrine()->getManager(); $contenido = $em->getRepository('EtsiSiteBundle:Contenido')->find($id); $data = $this->getForm($contenido); $view = new View($data); $view->setTemplate('EtsiSiteBundle:Form:newContenido.html.twig'); $view->setFormat('html'); return $this->get('fos_rest.view_handler')->handle($view); }
public function editSeccionAction($id) { $em = $this->getDoctrine()->getManager(); $seccion = $em->getRepository('EtsiSiteBundle:Seccion')->find($id); $data = $this->getForm($seccion); $view = new View($data); $view->setTemplate('EtsiSiteBundle:Form:newSeccion.html.twig'); $view->setFormat('html'); return $this->get('fos_rest.view_handler')->handle($view); }
/** * Lists all Article entities. * */ public function indexAction() { //echo phpinfo(); die; $em = $this->getDoctrine()->getManager(); $entities = $em->getRepository('MwRestBundle:Article')->findAll(); $view = new View(); $view->setData($entities); $view->setTemplateVar('entities'); $view->setTemplate('MwRestBundle:Article:index.html.twig'); return $this->container->get('fos_rest.view_handler')->handle($view); }
/** * Render js for VIE and a semantic editor. * * Hallo is a submodule of this bundle and available after right after you * followed the installation instructions. * To use aloha, you need to download the zip, as explained in step 8 of * the README. * * @param string $editor the name of the editor to load, currently hallo and aloha are supported */ public function includeJSFilesAction($editor = 'hallo') { // We could inject a list of names to template mapping for this // to allow adding other editors without changing this bundle $view = new View(); switch ($editor) { case 'hallo': if ($this->coffee) { $view->setTemplate('LiipVieBundle::includecoffeefiles-hallo.html.twig'); } else { $view->setTemplate('LiipVieBundle::includejsfiles-hallo.html.twig'); } break; case 'aloha': $view->setTemplate('LiipVieBundle::includejsfiles-aloha.html.twig'); break; default: throw new \InvalidArgumentException("Unknown editor '{$editor}' requested"); } return $this->viewHandler->handle($view); }
/** * Sets template to use for the encoding * * @param string|TemplateReference $template template to be used in the encoding * * @throws \InvalidArgumentException if the template is neither a string nor an instance of TemplateReference */ public function setTemplate($template) { if (!(is_string($template) || $template instanceof TemplateReference || $template instanceof Template)) { throw new \InvalidArgumentException('The template should be a string or extend TemplateReference'); } if (!is_string($template) && $template instanceof Template) { $this->setTemplate($template->getTemplate()); } else { parent::setTemplate($template); } return $this; }
/** * @ApiDoc( * section="Users", * description="Display the update form of the user", * input="AppBundle\Controller\Form\UserFormType", * output="AppBundle\Controller\UserController", * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="The user id"} * }, * statusCodes={ * 403="Returned when user will modify another one (Forbidden)", * 404="Returned when user wants modify a ghost (Not found)" * } * ) */ public function editUserAction($id) { // Here we check if the user is authorized to continue ... $sameUser = $this->get('check_auth')->sameUser($id, $this->getUser()); if (!$sameUser) { throw new HttpException(403, 'forbidden !'); } $rep = $this->getDoctrine()->getRepository('AppBundle:User'); $user = $rep->find($id); if (!$user) { throw new HttpException(404, 'this user doesn\'t exist'); } $form = $this->getForm($user, 'put_user', 'PUT', array('id' => $id)); $form->remove('plainPassword'); $view = new View($form); $view->setTemplate('AppBundle:User:edit.html.twig'); return $this->handleView($view); }
/** * Get the article * * @param string $article path * @return View view instance * * @ApiDoc() */ public function getArticleAction($article, Request $request, $_format) { $data = $this->createArticle($article); if ('xml' === $request->getRequestFormat()) { // Using SimpleThingsFormSerializerBundle // $serializer = $this->get('form_serializer'); // $data = $serializer->serialize($data, new ArticleType(), 'xml'); // return new Response($data); } // using explicit View creation $view = new View($data); // since we override the default handling for JSON, this will only affect XML //$view->setSerializerVersion('2.0'); //$view->setSerializerGroups(array('data')); // via a callback its possible to dynamically set anything on the serializer // the following example is essentially the same as $view->setSerializerGroups(array('data')); //$view->setSerializerCallback(function ($viewHandler, $serializer) { $serializer->setGroups(array('data')); } ); $view->setTemplate('LiipHelloBundle:Rest:getArticle.html.twig'); return $this->get('fos_rest.view_handler')->handle($view); }
/** * Renders the parameters and template and initializes a new response object with the * rendered content. * * @param GetResponseForControllerResultEvent $event A GetResponseForControllerResultEvent instance */ public function onKernelView(GetResponseForControllerResultEvent $event) { $request = $event->getRequest(); $view = $event->getControllerResult(); if (!$view instanceof View) { if (!$request->attributes->get('_view') && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) { return; } $view = new View($view); } if (null === $view->getFormat()) { $view->setFormat($request->getRequestFormat()); } $vars = $request->attributes->get('_template_vars'); if (!$vars) { $vars = $request->attributes->get('_template_default_vars'); } if (!empty($vars)) { $parameters = $view->getData(); if (null !== $parameters && !is_array($parameters)) { throw new \RuntimeException('View data must be an array if using a templating aware format.'); } $parameters = (array) $parameters; foreach ($vars as $var) { if (!array_key_exists($var, $parameters)) { $parameters[$var] = $request->attributes->get($var); } } $view->setData($parameters); } $viewHandler = $this->container->get('fos_rest.view_handler'); if ($viewHandler->isFormatTemplating($view->getFormat())) { $template = $request->attributes->get('_template'); if ($template) { if ($template instanceof TemplateReference) { $template->set('format', null); $template->set('engine', null); } $view->setTemplate($template); } } $response = $viewHandler->handle($view, $request); $event->setResponse($response); }
/** * Render javascript HTML tags for create.js and dependencies and bootstrap * javscript code. * * This bundle comes with templates for ckeditor, hallo and to develop on * the hallo coffeescript files. * * To use a different editor simply create a template following the naming * below: * CmfCreateBundle::includejsfiles-%editor%.html.twig * and pass the appropriate editor name. * * @param Request $request The request object for the AccessChecker. * @param string $editor the name of the editor to load. */ public function includeJSFilesAction(Request $request, $editor = 'ckeditor') { if (!$this->accessChecker->check($request)) { return new Response(''); } $view = new View(); $view->setTemplate(sprintf('CmfCreateBundle::includejsfiles-%s.html.twig', $editor)); if ($this->browserFileHelper) { $helper = $this->browserFileHelper->getEditorHelper($editor); $browseUrl = $helper ? $helper->getUrl() : false; } else { $browseUrl = false; } $view->setData(array('cmfCreateEditor' => $editor, 'cmfCreateStanbolUrl' => $this->stanbolUrl, 'cmfCreateImageUploadEnabled' => (bool) $this->imageUploadEnabled, 'cmfCreateFixedToolbar' => (bool) $this->fixedToolbar, 'cmfCreatePlainTextTypes' => json_encode($this->plainTextTypes), 'cmfCreateEditorBasePath' => $this->editorBasePath, 'cmfCreateBrowseUrl' => $browseUrl)); return $this->viewHandler->handle($view); }
/** * @ApiDoc( * section="Admin/Categories", * description="Display the update form of category", * input="AppBundle\Controller\Admin\Form\CategoryFormType", * output="AppBundle\Controller\Admin\AdminCategoryController", * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="The category's id"} * }, * statusCodes={ * 404="Returned when the category doesn't exist", * } * ) */ public function editCategoryAction($id) { $rep = $this->getDoctrine()->getRepository('AppBundle:Category'); $category = $rep->find($id); if (!$category) { throw new HttpException(404, 'this category doesn\'t exist'); } $form = $this->getForm($category, 'put_category', 'PUT', array('id' => $id)); $view = new View($form); $view->setTemplate('AppBundle:Category:edit.html.twig'); return $this->handleView($view); }
/** * @ApiDoc( * section="Items", * description="Display the items of an user", * output="AppBundle\Controller\ItemController", * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="The item's id"}, * }, * statusCodes={ * 404="Returned when the items didn't exist" * } * ) */ public function getItemsByUserAction($id) { $rep = $this->getDoctrine()->getRepository('AppBundle:Item'); $items = $rep->findBy(array('itemuserid' => $id)); if (!$items) { $view = $this->get('raiponce')->getView('Resources not Found!', 404); return $this->handleView($view); } $view = new View($items, 200); $view->setTemplate('AppBundle:Item:items.html.twig'); $view->setTemplateVar('items'); return $this->handleView($view); }
public function imagineAction() { $view = new View(); $view->setTemplate('LiipHelloBundle:Hello:imagine.html.twig'); return $this->viewHandler->handle($view); }