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


PHP ViewModel::setCaptureTo方法代码示例

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


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

示例1: testCollect

 public function testCollect()
 {
     $event = new MvcEvent();
     $layoutModel = new ViewModel();
     $layoutModel->setTemplate('layout/2cols-left');
     $event->setViewModel($layoutModel);
     $testBlock = new ViewModel();
     $testBlock->setTemplate('widget1');
     $testBlock->setCaptureTo('sidebarLeft');
     $testBlock2 = new ViewModel();
     $testBlock2->setOption('parent', 'test.block');
     $testBlock2->setTemplate('widget1');
     $this->blockPool->add('test.block', $testBlock);
     $this->blockPool->add('test.block2', $testBlock2);
     $this->collector->collect($event);
     $this->assertEquals('layout/2cols-left', $this->collector->getLayoutTemplate());
     $this->assertInternalType('array', $this->collector->getHandles());
     $this->assertContainsOnlyInstancesOf(HandleInterface::class, $this->collector->getHandles());
     $this->assertInternalType('array', $this->collector->getBlocks());
     $blocks = $this->collector->getBlocks();
     $testBlockArray = current($blocks);
     $testBlock2Array = array_pop($blocks);
     $this->assertEquals('test.block::content', $testBlock2Array['capture_to']);
     $this->assertContains('_files/view/widget1.phtml', $testBlockArray['template']);
     $this->assertEquals('sidebarLeft', $testBlockArray['capture_to']);
     $this->assertEquals(ViewModel::class, $testBlockArray['class']);
     $this->assertEquals(LayoutUpdaterInterface::AREA_DEFAULT, $this->collector->getCurrentArea());
     $this->assertInternalType('array', $this->collector->getLayoutStructure());
 }
开发者ID:hummer2k,项目名称:conlayout,代码行数:29,代码来源:LayoutCollectorTest.php

示例2: testGetCaptureTo

 public function testGetCaptureTo()
 {
     $viewModel = new ViewModel();
     $viewModel->setCaptureTo('root::footer');
     $viewModel->setOption('parent', 'some.parent');
     $layout = new TestLayout($this->updaterMock, $this->blockPool);
     $this->assertEquals(['some.parent', 'footer'], $layout->getCaptureTo($viewModel));
 }
开发者ID:hummer2k,项目名称:conlayout,代码行数:8,代码来源:LayoutTest.php

示例3: testCanMergeChildModelsWithoutCaptureToValues

 public function testCanMergeChildModelsWithoutCaptureToValues()
 {
     $this->renderer->setMergeUnnamedChildren(true);
     $root = new ViewModel(array('foo' => 'bar'));
     $child1 = new ViewModel(array('foo' => 'baz'));
     $child2 = new ViewModel(array('foo' => 'bar'));
     $child1->setCaptureTo(false);
     $child2->setCaptureTo('child2');
     $root->addChild($child1)->addChild($child2);
     $expected = array('foo' => 'baz', 'child2' => array('foo' => 'bar'));
     $test = $this->renderer->render($root);
     $this->assertEquals(json_encode($expected), $test);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:13,代码来源:JsonRendererTest.php

示例4: testCollect

 public function testCollect()
 {
     $event = new MvcEvent();
     $layoutModel = new ViewModel();
     $layoutModel->setTemplate('layout/2cols-left');
     $event->setViewModel($layoutModel);
     $testBlock = new ViewModel();
     $testBlock->setTemplate('test/block');
     $testBlock->setCaptureTo('sidebarLeft');
     $this->layout->addBlock('test.block', $testBlock);
     $this->collector->collect($event);
     $this->assertEquals('layout/2cols-left', $this->collector->getLayoutTemplate());
     $this->assertInternalType('array', $this->collector->getHandles());
     $this->assertContainsOnlyInstancesOf('ConLayout\\Handle\\HandleInterface', $this->collector->getHandles());
     $this->assertInternalType('array', $this->collector->getBlocks());
     $testBlockArray = current($this->collector->getBlocks());
     $this->assertEquals('test/block', $testBlockArray['template']);
     $this->assertEquals('sidebarLeft', $testBlockArray['capture_to']);
     $this->assertEquals('Zend\\View\\Model\\ViewModel', $testBlockArray['class']);
     $this->assertInternalType('array', $this->collector->getLayoutStructure());
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:21,代码来源:LayoutCollectorTest.php

示例5: testRendersSequentialChildrenWithNestedChildren

    public function testRendersSequentialChildrenWithNestedChildren()
    {
        $this->parent->setTemplate('complex');
        $child1 = $this->setupFirstChild();
        $child1->setTemplate('layout');
        $child1->setCaptureTo('content');

        $child2 = $this->setupSecondChild();
        $child2->setCaptureTo('sidebar');

        $nested = new ViewModel();
        $nested->setTemplate('child1');
        $nested->setCaptureTo('content');
        $child1->addChild($nested);

        $result = $this->renderer->render($this->parent);
        $this->assertRegExp('/Content:\s+Layout start\s+Content for layout\s+Layout end\s+Sidebar:\s+Second child/s', $result, $result);
    }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:18,代码来源:RenderChildModelTest.php

示例6: testCaptureToValueIsMutable

 public function testCaptureToValueIsMutable()
 {
     $model = new ViewModel();
     $model->setCaptureTo('foo');
     $this->assertEquals('foo', $model->captureTo());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:6,代码来源:ViewModelTest.php

示例7: testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRootViewModelToJsonRenderer

 public function testUsesTreeRendererInterfaceToDetermineWhetherOrNotToPassOnlyRootViewModelToJsonRenderer()
 {
     $jsonRenderer = new Renderer\JsonRenderer();
     $this->view->addRenderingStrategy(function ($e) use($jsonRenderer) {
         return $jsonRenderer;
     });
     $result = new stdClass();
     $this->view->addResponseStrategy(function ($e) use($result) {
         $result->content = $e->getResult();
     });
     $layout = new ViewModel(array('status' => 200));
     $content = new ViewModel(array('foo' => 'bar'));
     $content->setCaptureTo('response');
     $layout->addChild($content);
     $this->view->render($layout);
     $expected = json_encode(array('status' => 200, 'response' => array('foo' => 'bar')));
     $this->assertEquals($expected, $result->content);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:18,代码来源:ViewTest.php

示例8: build

 /**
  * @param $config
  * @param array $data
  * @return array|object|ViewModel
  */
 public function build($config, array $data = array())
 {
     $allOptions = $this->config->getOptions();
     $i = 0;
     $queue = new \SplQueue();
     $queue->enqueue($config);
     while ($queue->count() > 0) {
         $options = $queue->dequeue();
         $options = $this->config->applyInheritance($options);
         if (isset($options['viewModel'])) {
             $this->serviceLocator->setShared($options['viewModel'], false);
             $viewModel = $this->serviceLocator->get($options['viewModel']);
         } else {
             $viewModel = new ZendViewModel();
         }
         if ($i == 0) {
             $rootViewModel = $viewModel;
         }
         if (isset($options['template'])) {
             $viewModel->setTemplate($options['template']);
         }
         if (isset($options['capture'])) {
             $viewModel->setCaptureTo($options['capture']);
         } elseif (isset($options['id'])) {
             $viewModel->setCaptureTo($options['id']);
         }
         if (isset($options['data']['static'])) {
             $viewModel->setVariables($options['data']['static']);
         }
         if (isset($options['data']['fromGlobal'])) {
             $globalVar = $options['data']['fromGlobal'];
             if (is_array($globalVar)) {
                 foreach ($globalVar as $globalVarName => $viewVarName) {
                     $globalVarValue = $this->getVarValue($globalVarName, $data);
                     $viewModel->setVariable($viewVarName, $globalVarValue);
                 }
             } else {
                 $globalVarValue = $this->getVarValue($globalVar, $data);
                 $viewModel->setVariable($globalVar, $globalVarValue);
             }
         }
         if (isset($options['parent'])) {
             /** @var ViewModel $parent */
             $parent = $options['parent'];
             $parent->addChild($viewModel, $viewModel->captureTo(), true);
             if (isset($options['data']['fromParent'])) {
                 $varFromParent = $options['data']['fromParent'];
                 $parentVars = $parent->getVariables();
                 if (is_array($varFromParent)) {
                     foreach ($varFromParent as $varFromParentName => $viewVarName) {
                         $fromParentVal = $this->getVarValue($varFromParentName, $parentVars);
                         if ($fromParentVal === null) {
                             $fromParentVal = $parent->getVariable($varFromParentName);
                         }
                         if (is_array($viewVarName)) {
                             $dataFromParent = [];
                             foreach ($viewVarName as $varName) {
                                 $dataFromParent[$varName] = $fromParentVal;
                             }
                         } else {
                             $dataFromParent = [$viewVarName => $fromParentVal];
                         }
                         $viewModel->setVariables($dataFromParent);
                     }
                 } else {
                     $viewVarName = $options['data']['fromParent'];
                     $fromParentVal = $this->getVarValue($viewVarName, $parentVars);
                     if ($fromParentVal === null) {
                         $fromParentVal = $parent->getVariable($viewVarName);
                     }
                     $viewModel->setVariables([$viewVarName => $fromParentVal]);
                 }
             }
         }
         if (!empty($options['children'])) {
             foreach ($options['children'] as $childId => $child) {
                 if (is_string($child)) {
                     $childId = $child;
                     $child = $allOptions[$child];
                 }
                 if (isset($options['childrenDynamicLists'][$childId])) {
                     continue;
                 }
                 $child['id'] = $childId;
                 $child['parent'] = $viewModel;
                 $queue->enqueue($child);
             }
         }
         if (isset($options['childrenDynamicLists'])) {
             foreach ($options['childrenDynamicLists'] as $childName => $listName) {
                 $list = $viewModel->getVariable($listName);
                 if ($list === null) {
                     throw new \UnexpectedValueException("Cannot build children list of '{$childName}' by '{$listName}' list . View does not contain variable '{$listName}'.");
                 }
                 if (!is_array($list) && !$list instanceof \Traversable) {
//.........这里部分代码省略.........
开发者ID:sebaks,项目名称:view,代码行数:101,代码来源:ViewBuilder.php


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