本文整理汇总了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;
}
示例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);
}
示例3: postAction
public function postAction()
{
$todos = $this->getDoctrine()->getRepository('AppBundle:Todo')->findAll();
$view = new View();
$view->setData($todos);
return $this->handleView($view);
}
示例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);
}
示例5: createView
protected function createView($returnData)
{
$view = new View();
$view->setData($returnData);
$view->setStatusCode($returnData['status']);
$view->setFormat('json');
return $view;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例14: testPrepareTemplateParametersWithProvider
/**
* @dataProvider prepareTemplateParametersDataProvider
*/
public function testPrepareTemplateParametersWithProvider($viewData, $expected)
{
$handler = new ViewHandler();
$view = new View();
$view->setData($viewData);
$this->assertEquals($expected, $handler->prepareTemplateParameters($view));
}
示例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;
}