本文整理汇总了PHP中FOS\RestBundle\View\View::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setHeader方法的具体用法?PHP View::setHeader怎么用?PHP View::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\View\View
的用法示例。
在下文中一共展示了View::setHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleExtension
/**
* @param ViewHandler $viewHandler
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function handleExtension(ViewHandler $handler, View $view, Request $request, $format)
{
if (in_array("application/vnd.bpi.api+xml", $request->getAcceptableContentTypes())) {
$view->setHeader("Content-Type", "application/vnd.bpi.api+xml");
}
return $handler->createResponse($view, $request, "xml");
}
示例2: build
/**
* @return View
*/
public function build()
{
if ($this->setVersion && $this->singleDocument != null) {
$this->view->setHeader('ETag', hash('sha256', $this->singleDocument->getId() . $this->singleDocument->getVersion()));
}
return $this->view;
}
示例3: setContentRangeHeader
/**
* @param View $view
* @param int $offset
* @param int $limit
* @param int $total
*/
protected function setContentRangeHeader(View $view, $offset, $limit, $total)
{
$offset = (int) $offset;
$total = (int) $total;
$needRange = $limit >= 0 || $offset >= 0;
if ($needRange) {
if ($limit === null) {
$end = $total - 1;
} else {
$end = $offset + $limit - 1;
$end = min($end, $total - 1);
}
if ($limit !== null && (int) $limit === 0) {
$offset = '';
$end = '';
}
$view->setHeader('Content-Range', "items {$offset}-{$end}/{$total}");
}
$needPartialContentStatus = $offset > 0 || $limit !== null && $total > $limit;
if ($needPartialContentStatus) {
$view->setStatusCode(Response::HTTP_PARTIAL_CONTENT);
}
}
示例4: createResponse
/**
* Handles creation of a Response using either redirection or the templating/serializer service
*
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function createResponse(View $view, Request $request, $format)
{
$headers = $view->getHeaders();
if (empty($headers['Content-Type'])) {
$view->setHeader('Content-Type', $request->getMimeType($format));
}
$route = $view->getRoute();
$location = $route ? $this->getRouter()->generate($route, (array) $view->getData(), true) : $view->getLocation();
if ($location) {
return $this->createRedirectResponse($view, $location, $format);
}
if ($this->isFormatTemplating($format)) {
$content = $this->renderTemplate($view, $format);
} else {
$serializer = $this->getSerializer($view);
$content = $serializer->serialize($view->getData(), $format);
}
return new Response($content, $this->getStatusCode($view), $view->getHeaders());
}
示例5: postFlyAction
/**
* Creates a new fly from the submitted data.
*
* @throws AccessDeniedException
*
* @ApiDoc(
* resource = true,
* input = "Flyaround\DefaultBundle\Form\Type\FlyType",
* statusCodes = {
* 200 = "Returned when successful",
* 400 = "Returned when the form has errors"
* }
* )
*
* @Annotations\View(
* template = "FlyaroundDefaultBundle:Fly:newFly.html.twig",
* statusCode = Codes::HTTP_BAD_REQUEST
* )
*
* @param Request $request the request object
*
* @return FormTypeInterface|RouteRedirectView
*/
public function postFlyAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$fly = new Fly();
$form = $this->createForm(new FlyType(), $fly);
$form->submit($request);
if ($form->isValid()) {
$em->persist($fly);
$em->flush();
return new Response('{"id": ' . $fly->getId() . '}', 201, array('Access-Control-Allow-Origin' => '*'));
}
$view = new View(array('form' => $form));
$view->setHeader('Access-Control-Allow-Origin', '*');
$group = $this->container->get('security.context')->isGranted('ROLE_API') ? 'restapi' : 'standard';
$view->getSerializationContext()->setGroups(array('Default', $group));
return $view;
}