當前位置: 首頁>>代碼示例>>PHP>>正文


PHP JsonModel::setCaptureTo方法代碼示例

本文整理匯總了PHP中Zend\View\Model\JsonModel::setCaptureTo方法的典型用法代碼示例。如果您正苦於以下問題:PHP JsonModel::setCaptureTo方法的具體用法?PHP JsonModel::setCaptureTo怎麽用?PHP JsonModel::setCaptureTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\View\Model\JsonModel的用法示例。


在下文中一共展示了JsonModel::setCaptureTo方法的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: testChildrenMayInvokeDifferentRenderingStrategiesThanParents

 public function testChildrenMayInvokeDifferentRenderingStrategiesThanParents()
 {
     $this->view->addRenderingStrategy(function ($e) {
         $model = $e->getModel();
         if (!$model instanceof ViewModel) {
             return;
         }
         return new TestAsset\Renderer\VarExportRenderer();
     });
     $this->view->addRenderingStrategy(function ($e) {
         $model = $e->getModel();
         if (!$model instanceof JsonModel) {
             return;
         }
         return new Renderer\JsonRenderer();
     }, 10);
     // higher priority, so it matches earlier
     $this->result = $result = new stdClass();
     $this->view->addResponseStrategy(function ($e) use($result) {
         $result->content = $e->getResult();
     });
     $child1 = new ViewModel(array('foo' => 'bar'));
     $child1->setCaptureTo('child1');
     $child2 = new JsonModel(array('bar' => 'baz'));
     $child2->setCaptureTo('child2');
     $child2->setTerminal(false);
     $this->model->setVariable('parent', 'node');
     $this->model->addChild($child1);
     $this->model->addChild($child2);
     $this->view->render($this->model);
     $expected = var_export(new ViewVariables(array('parent' => 'node', 'child1' => var_export(array('foo' => 'bar'), true), 'child2' => json_encode(array('bar' => 'baz')))), true);
     $this->assertEquals($expected, $this->result->content);
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:33,代碼來源:ViewTest.php


注:本文中的Zend\View\Model\JsonModel::setCaptureTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。