本文整理汇总了PHP中FOS\RestBundle\View\View类的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: createResponse
/**
* Handles response for csv-request.
*
* @param ViewHandler $handler
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*
* @throws ObjectNotSupportedException
*/
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
if (!$view->getData() instanceof ListRepresentation) {
throw new ObjectNotSupportedException($view);
}
$viewData = $view->getData();
$data = new CallbackCollection($viewData->getData(), [$this, 'prepareData']);
$fileName = sprintf('%s.csv', $viewData->getRel());
$config = new ExporterConfig();
$exporter = new Exporter($config);
$data->rewind();
if ($row = $data->current()) {
$config->setColumnHeaders(array_keys($row));
}
$config->setDelimiter($this->convertValue($request->get('delimiter', ';'), self::$delimiterMap));
$config->setNewline($this->convertValue($request->get('newLine', '\\n'), self::$newLineMap));
$config->setEnclosure($request->get('enclosure', '"'));
$config->setEscape($request->get('escape', '\\'));
$response = new StreamedResponse();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $fileName, $fileName);
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', $disposition);
$response->setCallback(function () use($data, $exporter) {
$exporter->export('php://output', $data);
});
$response->send();
return $response;
}
开发者ID:sulu,项目名称:sulu,代码行数:40,代码来源:CsvHandler.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: getStatusCode
/**
* FOSRest's ViewHandler has a private getStatusCode method. Because we cannot use it, we added
* this lightweight method (without forms support) for Hal custom handler.
*
* @param View $view view instance
*
* @return int HTTP status code
*/
private function getStatusCode(View $view)
{
if (null !== ($code = $view->getStatusCode())) {
return $code;
}
return Codes::HTTP_OK;
}
开发者ID:sparrowDom,项目名称:pigapi,代码行数:15,代码来源:HalViewHandler.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: createFeed
/**
* @param $data array
* @param format string, either rss or atom
*/
protected function createFeed(View $view, Request $request)
{
$feed = new Feed();
$data = $view->getData();
$item = current($data);
$annotationData = $this->reader->read($item);
if ($item && ($feedData = $annotationData->getFeed())) {
$class = get_class($item);
$feed->setTitle($feedData->getName());
$feed->setDescription($feedData->getDescription());
$feed->setLink($this->urlGen->generateCollectionUrl($class));
$feed->setFeedLink($this->urlGen->generateCollectionUrl($class, $request->getRequestFormat()), $request->getRequestFormat());
} else {
$feed->setTitle('Camdram feed');
$feed->setDescription('Camdram feed');
}
$lastModified = null;
$accessor = PropertyAccess::createPropertyAccessor();
// Add one or more entries. Note that entries must be manually added once created.
foreach ($data as $document) {
$entry = $feed->createEntry();
$entry->setTitle($accessor->getValue($document, $feedData->getTitleField()));
$entry->setLink($this->urlGen->generateUrl($document));
$entry->setDescription($this->twig->render($feedData->getTemplate(), array('entity' => $document)));
if ($accessor->isReadable($document, $feedData->getUpdatedAtField())) {
$entry->setDateModified($accessor->getValue($document, $feedData->getUpdatedAtField()));
}
$feed->addEntry($entry);
if (!$lastModified || $entry->getDateModified() > $lastModified) {
$lastModified = $entry->getDateModified();
}
}
$feed->setDateModified($lastModified);
return $feed->export($request->getRequestFormat());
}
开发者ID:dstansby,项目名称:camdram,代码行数:39,代码来源:FeedViewHandler.php
示例6: 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");
}
开发者ID:rimi-itk,项目名称:bpi-web-service,代码行数:15,代码来源:BPIViewHandler.php
示例7: 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
示例8: indexAction
/**
* @Route("/")
*/
public function indexAction()
{
$view = new View();
$view->setFormat('html');
$view->setTemplate('TastdCoreBundle:Default:index.html.twig');
return $view;
}
开发者ID:oriodesign,项目名称:tastd-backend-demo,代码行数:10,代码来源:DefaultController.php
示例9: postUserSignInAction
/**
* Sign in users by pair username:password.
*
* @ApiDoc(
* views={"default", "user"},
* section="Security API",
* resource=true,
* resourceDescription="Sign in users by pair username:password.",
* statusCodes={
* 200="Returned when successful",
* 400="Returned when an error has occurred",
* }
* )
*
* @Rest\Route("/sign-in", requirements={
* "_format": "json|xml"
* })
*
* @Rest\RequestParam(name="username", requirements="[\w\-]+", nullable=false, description="Username")
* @Rest\RequestParam(name="password", nullable=false, description="Password")
*
* @param ParamFetcherInterface $paramFetcher
* @return View
*/
public function postUserSignInAction(ParamFetcherInterface $paramFetcher)
{
$username = $paramFetcher->get('username');
$password = $paramFetcher->get('password');
/** @var EntityRepository $repository */
$repository = $this->getDoctrine()->getManager()->getRepository('UserBundle:User');
/** @var User $user */
$user = $repository->findOneBy(['username' => $username]);
if (!$user || !$this->validatePassword($user, $password)) {
return new View(array('message' => 'User not found.'), 400);
}
if (!$user->isEnabled()) {
return new View(array('message' => 'Account is disabled.'), 400);
}
if (!$user->isAccountNonLocked()) {
return new View(array('message' => 'Account is locked.'), 400);
}
if (!$user->isAccountNonExpired()) {
return new View(array('message' => 'Account is expired.'), 400);
}
if (!$user->isCredentialsNonExpired()) {
return new View(array('message' => 'Credentials is expired.'), 400);
}
$this->generateToken($user);
$this->getDoctrine()->getManager()->flush();
$headers = array('Token' => $user->getApiToken(), 'ExpireAt' => $user->getApiTokenExpireAt()->format('c'), 'Username' => $user->getUsername());
$view = new View(array_merge(array('user' => $user->getId()), $headers), 200, $headers);
$this->setAuthInfoInCookie($headers, $view->getResponse(), $user->getApiTokenExpireAt());
return $view;
}
开发者ID:glavweb,项目名称:symfony-rest,代码行数:54,代码来源:SecurityApiController.php
示例10: handle
public function handle(RequestConfiguration $requestConfiguration, View $view)
{
if ($view->getResponse()->getContent()) {
return $view->getResponse();
}
return parent::handle($requestConfiguration, $view);
}
开发者ID:enhavo,项目名称:enhavo,代码行数:7,代码来源:ViewHandler.php
示例11: newUserAction
/**
* @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);
}
开发者ID:Hemric,项目名称:rentitapi,代码行数:16,代码来源:AdminUserController.php
示例12: 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
示例13: createResponse
/**
* Converts the viewdata to a RSS feed. Modify to suit your datastructure.
*
* @return Response
*/
public function createResponse(ViewHandler $handler, View $view, Request $request)
{
if ($view->getData() instanceof Diary) {
return new Response($this->createFeed($view->getData()), Response::HTTP_OK, $view->getHeaders());
} else {
return new Response('Unsupported entity type', Response::HTTP_BAD_REQUEST);
}
}
开发者ID:dstansby,项目名称:camdram,代码行数:13,代码来源:ICalViewHandler.php
示例14: 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
示例15: getCountryAction
/**
* Информация о стране по id
*
* @param Country $country
*
* @Rest\Get("countries/{id}", requirements={"id"="\d+"})
* @ParamConverter("country", class="VifeedGeoBundle:Country")
* @ApiDoc(
* section="Campaign API",
* requirements={
* {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="id страны"}
* },
* output={
* "class"="Vifeed\GeoBundle\Entity\Country",
* "groups"={"default"}
* },
* statusCodes={
* 200="Returned when successful",
* 403="Returned when the user is not authorized to use this method",
* 404="Returned when campaign not found"
* }
* )
*
* @return Response
*/
public function getCountryAction(Country $country)
{
$context = new SerializationContext();
$context->setGroups(['default']);
$view = new View($country);
$view->setSerializationContext($context);
return $this->handleView($view);
}
开发者ID:bzis,项目名称:zomba,代码行数:33,代码来源:CountryController.php
示例16: testCreateResponseWithLocation
/**
* @dataProvider createResponseWithLocationDataProvider
*/
public function testCreateResponseWithLocation($expected, $format, $forceRedirects)
{
$viewHandler = new ViewHandler(array('html' => true, 'json' => false, 'xml' => false), Codes::HTTP_BAD_REQUEST, $forceRedirects);
$view = new View();
$view->setLocation('foo');
$returnedResponse = $viewHandler->createResponse($view, new Request(), $format);
$this->assertEquals($expected, $returnedResponse->getStatusCode());
$this->assertEquals('foo', $returnedResponse->headers->get('location'));
}
开发者ID:richardmiller,项目名称:FOSRestBundle,代码行数:12,代码来源:ViewHandlerTest.php
示例17: renderResponse
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);
}
开发者ID:symfony-cmf,项目名称:blog-bundle,代码行数:9,代码来源:BlogController.php
示例18: createResponse
/**
* @param ViewHandler $viewHandler
* @param View $view
* @param Request $request
* @param string $format
*/
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
{
$fosrestview = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$fosrestview .= '<rss version="2.0">';
$fosrestview .= '<channel>';
$fosrestview .= '<title>Get Afspraken</title>';
$fosrestview .= '<language>en-us</language>';
return new Response($fosrestview, 200, $view->getHeaders());
}
开发者ID:PieterSwitten,项目名称:webandmobile,代码行数:15,代码来源:FosRestView.php
示例19: getUserAction
/**
* Информация о юзере
*
* @ApiDoc(
* section="User API",
* output={
* "class"="Vifeed\UserBundle\Entity\User",
* "groups"={"user"}
* },
* statusCodes={
* 200="Returned when successful",
* 403="Returned when the user is not authorized to use this method"
* }
* )
*
* @Rest\Get("users/current")
*
* @return Response
*/
public function getUserAction()
{
$user = $this->getUser();
$context = new SerializationContext();
$context->setGroups(array('user'));
$view = new View($user);
$view->setSerializationContext($context);
return $this->handleView($view);
}
开发者ID:bzis,项目名称:zomba,代码行数:28,代码来源:UserController.php
示例20: 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
注:本文中的FOS\RestBundle\View\View类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论