當前位置: 首頁>>代碼示例>>PHP>>正文


PHP View::setData方法代碼示例

本文整理匯總了PHP中FOS\RestBundle\View\View::setData方法的典型用法代碼示例。如果您正苦於以下問題:PHP View::setData方法的具體用法?PHP View::setData怎麽用?PHP View::setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在FOS\RestBundle\View\View的用法示例。


在下文中一共展示了View::setData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setDocument

 /**
  * @param Document $document
  * @return ViewBuilder
  */
 public function setDocument(Document $document)
 {
     $this->singleDocument = $document;
     $resourceClass = $this->resourceClass;
     $this->view->setData($resourceClass::createFromReadModel($document));
     return $this;
 }
開發者ID:EightArmCode,項目名稱:librarian,代碼行數:11,代碼來源:ViewBuilder.php

示例2: showAction

 public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
 {
     $view = new View();
     $view->setData(json_decode($exception->getMessage(), true));
     $view->setFormat('json');
     return $this->container->get('fos_rest.view_handler')->handle($view);
 }
開發者ID:syedomair,項目名稱:SymfonyAPIProject,代碼行數:7,代碼來源:CustomExceptionController.php

示例3: postAction

 public function postAction()
 {
     $todos = $this->getDoctrine()->getRepository('AppBundle:Todo')->findAll();
     $view = new View();
     $view->setData($todos);
     return $this->handleView($view);
 }
開發者ID:profesorasix,項目名稱:TodoRest,代碼行數:7,代碼來源:TodoController.php

示例4: includeJSFilesAction

 /**
  * 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);
 }
開發者ID:notsentient,項目名稱:CreateBundle,代碼行數:34,代碼來源:JsloaderController.php

示例5: createView

 protected function createView($returnData)
 {
     $view = new View();
     $view->setData($returnData);
     $view->setStatusCode($returnData['status']);
     $view->setFormat('json');
     return $view;
 }
開發者ID:syedomair,項目名稱:SymfonyAPIProject,代碼行數:8,代碼來源:BaseFOSRestController.php

示例6: validationFailureAction

 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);
 }
開發者ID:nashidgit,項目名稱:LiipHelloBundle,代碼行數:17,代碼來源:HelloController.php

示例7: converterAction

 /**
  * 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);
 }
開發者ID:nashidgit,項目名稱:LiipHelloBundle,代碼行數:14,代碼來源:PHPCRController.php

示例8: getAuthorityAction

 /**
  * @ApiDoc(
  *   resource = true,
  *   description = "Retrieves the health authority data for a postcode",
  *   statusCodes = {
  *     200 = "Returned when successful",
  *     400 = "Returned when there is a data error",
  *     404 = "Returned when no entities are found"
  *   }
  * )
  *
  * @param string $postcode
  * @return View
  */
 public function getAuthorityAction($postcode)
 {
     $result = $this->getService()->findByPostCode(strtolower(str_replace(' ', '', $postcode)));
     $view = new View();
     $view->setData($result);
     if (!count($result)) {
         $view->setStatusCode(404);
     }
     return $view;
 }
開發者ID:TransformCore,項目名稱:HayPersistenceApi,代碼行數:24,代碼來源:AuthorityController.php

示例9: indexAction

 /**
  * 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);
 }
開發者ID:BBinsse,項目名稱:test,代碼行數:15,代碼來源:ArticleController.php

示例10: createResponse

 /**
  * @param ViewHandler   $handler
  * @param View          $view
  * @param Request       $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function createResponse(ViewHandler $handler, View $view, Request $request)
 {
     $format = $view->getFormat() ?: $request->getRequestFormat();
     $data = $view->getData();
     if ($data instanceof Cursor) {
         $view->setData(iterator_to_array($data, false));
         $view->getResponse()->headers->set('X-Total-Count', $data->count());
         return $handler->createResponse($view, $request, $view->getFormat());
     }
     if ($data instanceof Form && Codes::HTTP_BAD_REQUEST === $view->getStatusCode()) {
         $view->setData($this->formatFormErrors($data));
         return $handler->createResponse($view, $request, $format);
     }
     return $handler->createResponse($view, $request, $format);
 }
開發者ID:nass59,項目名稱:Lab,代碼行數:22,代碼來源:PaginatedViewHandler.php

示例11: getUserAction

 /**
  * @ApiDoc
  *
  * @param integer $objectId            
  * @throws NotFoundHttpException
  */
 public function getUserAction($userId = 0)
 {
     /* @var $model \App\ModuleObjectsBundle\Model\MapObjectModel */
     $model = $this->container->get('app_module_user.model.user');
     $data = $model->findOneById($userId);
     if (null === $data) {
         throw new NotFoundHttpException();
     }
     $view = new View();
     $view->setData($data);
     $context = new SerializationContext();
     $context->setGroups(array('.all', 'user.get'));
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
開發者ID:amin1984,項目名稱:Behat,代碼行數:21,代碼來源:UsersController.php

示例12: onKernelView

 /**
  * 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);
 }
開發者ID:richardmiller,項目名稱:FOSRestBundle,代碼行數:50,代碼來源:ViewResponseListener.php

示例13: setViewData

 /**
  * @param IsIdentifiable $viewData
  * @param string         $grouping
  * @return View
  */
 protected function setViewData(IsIdentifiable $viewData, $grouping = self::DEFAULT_API_GROUPING)
 {
     $this->view->setData($viewData);
     $this->setGrouping($grouping);
     return $this->view;
 }
開發者ID:TransformCore,項目名稱:HayPersistenceApi,代碼行數:11,代碼來源:RestfulService.php

示例14: testPrepareTemplateParametersWithProvider

 /**
  * @dataProvider prepareTemplateParametersDataProvider
  */
 public function testPrepareTemplateParametersWithProvider($viewData, $expected)
 {
     $handler = new ViewHandler();
     $view = new View();
     $view->setData($viewData);
     $this->assertEquals($expected, $handler->prepareTemplateParameters($view));
 }
開發者ID:shreyans264,項目名稱:symfonyPlayGround,代碼行數:10,代碼來源:ViewHandlerTest.php

示例15: putDistrictCouncilDetailsAction

 /**
  * @ApiDoc(
  *   resource = true,
  *   description = "Adds a website the district council data set",
  *   statusCodes = {
  *     200 = "Returned when successful",
  *     400 = "Returned when there is a data error",
  *     404 = "Returned when no entities are found"
  *   }
  * )
  *
  * @param string       $entityCode
  * @param ParamFetcher $paramFetcher
  *
  * @RequestParam(name="url", nullable=false, strict=true, description="The url of the district council website")
  * @RequestParam(name="council_name", nullable=false, strict=true, description="The display name for the disctrict council")
  *
  * @return View
  */
 public function putDistrictCouncilDetailsAction($entityCode, ParamFetcher $paramFetcher)
 {
     /** @var DistrictCouncil $result */
     $result = $this->getService()->findByEntityCode(new DistrictCouncil($entityCode, ''));
     $result->setDistrictCouncilName($paramFetcher->get('council_name'))->setWebsite($paramFetcher->get('url'))->setLastUpdated(new \DateTime());
     $result = $this->getService()->saveDistrictCouncil($result);
     $view = new View();
     $view->setData($result);
     if (null === $result->getId()) {
         $view->setStatusCode(404);
     }
     return $view;
 }
開發者ID:TransformCore,項目名稱:HayPersistenceApi,代碼行數:32,代碼來源:DistrictCouncilController.php


注:本文中的FOS\RestBundle\View\View::setData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。