当前位置: 首页>>代码示例>>PHP>>正文


PHP View::setTemplateVar方法代码示例

本文整理汇总了PHP中FOS\RestBundle\View\View::setTemplateVar方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setTemplateVar方法的具体用法?PHP View::setTemplateVar怎么用?PHP View::setTemplateVar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FOS\RestBundle\View\View的用法示例。


在下文中一共展示了View::setTemplateVar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getView

 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;
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:8,代码来源:Raiponce.php

示例2: getClaimedByUserAction

 /**
  * @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);
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:19,代码来源:ClaimController.php

示例3: getUsersAction

 /**
  * @ApiDoc(
  *  section="Admin/Users",
  *  description="Display all the users",
  *  output="AppBundle\Controller\Admin\AdminUserController",
  * )
  */
 public function getUsersAction()
 {
     $rep = $this->getDoctrine()->getRepository('AppBundle:User');
     $users = $rep->findAll();
     $view = new View($users);
     $view->setTemplate('AppBundle:User:users.html.twig');
     $view->setTemplateVar('users');
     return $this->handleView($view);
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:16,代码来源:AdminUserController.php

示例4: getCategoryItemsAction

 /**
  * @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);
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:20,代码来源:CategoryController.php

示例5: 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

示例6: 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();
     $configuration = $request->attributes->get('_view');
     $view = $event->getControllerResult();
     if (!$view instanceof View) {
         if (!$configuration && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) {
             return parent::onKernelView($event);
         }
         $view = new View($view);
     }
     if ($configuration) {
         if ($configuration->getTemplateVar()) {
             $view->setTemplateVar($configuration->getTemplateVar());
         }
         if (null === $view->getStatusCode() && $configuration->getStatusCode()) {
             $view->setStatusCode($configuration->getStatusCode());
         }
         if ($configuration->getSerializerGroups()) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->setGroups($configuration->getSerializerGroups());
             $view->setSerializationContext($context);
         }
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     $viewHandler = $this->container->get('fos_rest.view_handler');
     if ($viewHandler->isFormatTemplating($view->getFormat())) {
         if (!empty($vars)) {
             $parameters = (array) $viewHandler->prepareTemplateParameters($view);
             foreach ($vars as $var) {
                 if (!array_key_exists($var, $parameters)) {
                     $parameters[$var] = $request->attributes->get($var);
                 }
             }
             $view->setData($parameters);
         }
         $template = $request->attributes->get('_template');
         if ($template) {
             if ($template instanceof TemplateReference) {
                 $template->set('format', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:59,代码来源:ViewResponseListener.php

示例7: getUserAction

 /**
  * @ApiDoc(
  *  section="Users",
  *  description="Display the creation form of the user",
  *  output="AppBundle\Controller\UserController",
  *  parameters={
  *      {"name"="id", "dataType"="integer", "required"=true, "description"="The user's id"}
  *  },
  *  statusCodes={
  *         404="Returned when someone"
  *  }
  * )
  */
 public function getUserAction($id)
 {
     // On enlève les informations sensibles
     $self = $this->getUser();
     $user = null;
     if ($self->hasRole('ROLE_ADMIN')) {
         $rep = $this->getDoctrine()->getRepository('AppBundle:User');
         $user = $rep->find($id);
     } else {
         if ($self->hasRole('ROLE_USER')) {
             $user = $this->getDoctrine()->getManager()->getRepository('AppBundle:User')->findForUsers($id);
         }
     }
     if (!$user) {
         throw new HttpException(404, 'user not found');
     }
     $view = new View($user);
     $view->setTemplate('AppBundle:User:details.html.twig');
     $view->setTemplateVar('details');
     return $this->handleView($view);
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:34,代码来源:UserController.php

示例8: onKernelView

 /**
  * Renders the parameters and template and initializes a new response object with the
  * rendered content.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     /** @var \FOS\RestBundle\Controller\Annotations\View $configuration */
     $configuration = $request->attributes->get('_view');
     $view = $event->getControllerResult();
     $customViewDefined = true;
     if (!$view instanceof View) {
         if (!$configuration && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) {
             return parent::onKernelView($event);
         }
         $view = new View($view);
         $customViewDefined = false;
     }
     if ($configuration) {
         if ($configuration->getTemplateVar()) {
             $view->setTemplateVar($configuration->getTemplateVar());
         }
         if ($configuration->getStatusCode() && (null === $view->getStatusCode() || Codes::HTTP_OK === $view->getStatusCode())) {
             $view->setStatusCode($configuration->getStatusCode());
         }
         if ($configuration->getSerializerGroups() && !$customViewDefined) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->setGroups($configuration->getSerializerGroups());
             $view->setSerializationContext($context);
         }
         if ($configuration->getSerializerEnableMaxDepthChecks()) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->enableMaxDepthChecks();
             $view->setSerializationContext($context);
         }
         $populateDefaultVars = $configuration->isPopulateDefaultVars();
     } else {
         $populateDefaultVars = true;
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars && $populateDefaultVars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     $viewHandler = $this->container->get('fos_rest.view_handler');
     if ($viewHandler->isFormatTemplating($view->getFormat())) {
         if (!empty($vars)) {
             $parameters = (array) $viewHandler->prepareTemplateParameters($view);
             foreach ($vars as $var) {
                 if (!array_key_exists($var, $parameters)) {
                     $parameters[$var] = $request->attributes->get($var);
                 }
             }
             $view->setData($parameters);
         }
         $template = $request->attributes->get('_template');
         if ($template) {
             if ($template instanceof TemplateReference) {
                 $template->set('format', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:juliettemijeon,项目名称:BDDProducts,代码行数:70,代码来源:ViewResponseListener.php

示例9: getItemsByUserAction

 /**
  * @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);
 }
开发者ID:Hemric,项目名称:rentitapi,代码行数:26,代码来源:ItemController.php

示例10: onKernelView

 /**
  * Renders the parameters and template and initializes a new response object with the
  * rendered content.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
         return false;
     }
     /** @var \FOS\RestBundle\Controller\Annotations\View $configuration */
     $configuration = $request->attributes->get('_view');
     $view = $event->getControllerResult();
     $customViewDefined = true;
     if (!$view instanceof View) {
         if (!$configuration && !$this->forceView) {
             return;
         }
         $view = new View($view);
         $customViewDefined = false;
     }
     if ($configuration) {
         if ($configuration->getTemplateVar()) {
             $view->setTemplateVar($configuration->getTemplateVar());
         }
         if ($configuration->getStatusCode() && (null === $view->getStatusCode() || Response::HTTP_OK === $view->getStatusCode())) {
             $view->setStatusCode($configuration->getStatusCode());
         }
         $context = $view->getContext();
         if ($configuration->getSerializerGroups() && !$customViewDefined) {
             $context->addGroups($configuration->getSerializerGroups());
         }
         if ($configuration->getSerializerEnableMaxDepthChecks()) {
             $context->setMaxDepth(0);
         }
         $populateDefaultVars = $configuration->isPopulateDefaultVars();
     } else {
         $populateDefaultVars = true;
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars && $populateDefaultVars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     if ($this->viewHandler->isFormatTemplating($view->getFormat()) && !$view->getRoute() && !$view->getLocation()) {
         if (!empty($vars)) {
             $parameters = (array) $this->viewHandler->prepareTemplateParameters($view);
             foreach ($vars as $var) {
                 if (!array_key_exists($var, $parameters)) {
                     $parameters[$var] = $request->attributes->get($var);
                 }
             }
             $view->setData($parameters);
         }
         $template = null !== $configuration && $configuration->getTemplate() ? $configuration->getTemplate() : $request->attributes->get('_template');
         if ($template && !$view->getTemplate()) {
             if ($template instanceof TemplateReferenceInterface) {
                 $template->set('format', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $this->viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:69,代码来源:ViewResponseListener.php


注:本文中的FOS\RestBundle\View\View::setTemplateVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。