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


PHP JsonModel::addChild方法代码示例

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


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

示例1: testRecursesJsonModelChildrenWhenRendering

 /**
  * @group 2463
  */
 public function testRecursesJsonModelChildrenWhenRendering()
 {
     $root = new JsonModel(array('foo' => 'bar'));
     $child1 = new JsonModel(array('foo' => 'bar'));
     $child2 = new JsonModel(array('foo' => 'bar'));
     $child1->setCaptureTo('child1');
     $child2->setCaptureTo('child2');
     $root->addChild($child1)->addChild($child2);
     $expected = array('foo' => 'bar', 'child1' => array('foo' => 'bar'), 'child2' => array('foo' => 'bar'));
     $test = $this->renderer->render($root);
     $this->assertEquals(json_encode($expected), $test);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:15,代码来源:JsonRendererTest.php

示例2: create

 public function create($data)
 {
     $router = $this->serviceLocator->get('router');
     $controllerLoader = $this->serviceLocator->get('controllerLoader');
     foreach ($data as $key => $requestData) {
         $request = new Request();
         $request->setMethod($requestData['method']);
         $request->setUri($requestData['uri']);
         $queryString = $request->getUri()->getQuery();
         if ($queryString) {
             $query = [];
             parse_str($queryString, $query);
             $request->setQuery(new Parameters($query));
         }
         if (isset($requestData['headers'])) {
             foreach ($requestData['headers'] as $name => $value) {
                 $request->getHeaders()->addHeaderLine($name, $value);
             }
         }
         $request->getHeaders()->addHeaders([$this->request->getHeaders()->get('Accept'), $this->request->getHeaders()->get('Content-Type')]);
         if (isset($requestData['content'])) {
             $request->setContent(json_encode($requestData['content']));
         }
         $response = new Response();
         $event = new MvcEvent();
         $event->setRequest($request);
         $event->setResponse($response);
         $match = $router->match($request);
         RouteListener::resolveController($match);
         $contentModel = null;
         if (!isset($match) || $match->getMatchedRouteName() != 'rest.' . $this->options->getManifestName()) {
             $contentModel = $this->createExceptionContentModel(new Exception\RuntimeException(sprintf('%s uri is not a rest route, so is not supported by batch controller.', $requestData['uri'])), $event);
         } else {
             try {
                 $controller = $controllerLoader->get($match->getParam('controller'));
             } catch (\Zend\ServiceManager\Exception\ServiceNotFoundException $exception) {
                 $contentModel = $this->createExceptionContentModel($exception, $event);
                 $response->setStatusCode(404);
             }
             $event->setRouteMatch($match);
             $controller->setEvent($event);
             if (!isset($contentModel)) {
                 try {
                     $contentModel = $controller->dispatch($request, $response);
                 } catch (\Exception $exception) {
                     $contentModel = $this->createExceptionContentModel($exception, $event);
                 }
             }
         }
         $headers = [];
         foreach ($response->getHeaders() as $header) {
             $headers[$header->getFieldName()] = $header->getFieldValue();
         }
         $responseModel = new JsonModel(['status' => $response->getStatusCode(), 'headers' => $headers]);
         if ($contentModel instanceof ModelInterface) {
             $responseModel->addChild($contentModel, 'content');
         }
         $this->model->addChild($responseModel, $key);
     }
     return $this->model;
 }
开发者ID:superdweebie,项目名称:doctrine-extensions-module,代码行数:61,代码来源:BatchJsonRestfulController.php


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