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


PHP ViewModel::captureTo方法代码示例

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


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

示例1: testCaptureToValueIsMutable

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

示例2: canonizeActionResult

 /**
  * Inspect the result, and cast it to a ViewModel
  *
  * @param  MvcEvent $e
  * @return void
  */
 public function canonizeActionResult(MvcEvent $e)
 {
     $result = $e->getResult();
     if ($result instanceof Response) {
         return;
     }
     // MVC controller
     $controller = $e->getTarget();
     // Controller view
     $controllerVew = $controller->plugin('view');
     // Collect captured contents
     if ($this->obStarted) {
         $content = ob_get_clean();
         if ($content) {
             if (null === $result && !$controllerVew->hasViewModel()) {
                 $result = $content;
             } elseif (Pi::service()->hasService('log')) {
                 Pi::service('log')->info('Captured content: ' . $content);
             }
         }
     }
     // Skip scalar result
     if (!$this->type && is_scalar($result) && !is_bool($result)) {
         if ($controllerVew->hasViewModel()) {
             $viewModel = $controllerVew->getViewModel();
         } else {
             $viewModel = new ViewModel();
         }
         $viewModel->setTemplate('__NULL__');
         $viewModel->setVariable($viewModel->captureTo(), $result);
         $e->setResult($viewModel);
         return;
     }
     // ViewModel generated by controller
     $viewModel = null;
     // Cast controller ViewModel
     if ($controllerVew->hasViewModel()) {
         $viewModel = $controllerVew->getViewModel();
         $template = $viewModel->getTemplate();
         // Controller ViewModel is as the main model if if if is specified
         // with template, MvcEvent result is converted to variables of
         // the ViewModel
         if ($viewModel instanceof ViewModel && !$viewModel instanceof JsonModel && !$viewModel instanceof FeedModel && $template && '__NULL__' != $template) {
             $variables = array();
             $options = array();
             if ($result instanceof ViewModel) {
                 $variables = $result->getVariables();
                 $options = $result->getOptions();
             } elseif ($result instanceof FeedDataModel) {
                 $variables = (array) $result;
                 $options = array('feed_type' => $result->getType());
             } elseif (ArrayUtils::hasStringKeys($result, true)) {
                 $variables = array_merge_recursive($variables, $result);
             }
             $viewModel->setVariables($variables);
             $viewModel->setOptions($options);
             $e->setResult($viewModel);
             return;
         }
     }
     // Set type to json if no template is specified
     if (!$this->type && null !== $result) {
         $skip = false;
         if ($result instanceof ViewModel && $result->getTemplate() && $result->getTemplate() != '__NULL__' || $result instanceof JsonModel || $result instanceof FeedModel) {
             $skip = true;
         }
         if (!$skip) {
             $this->type = 'json';
             Pi::service('log')->mute();
         }
     }
     // Cast controller view model to result ViewModel
     switch ($this->type) {
         // For Feed
         case 'feed':
             if ($result instanceof FeedModel) {
                 $model = $result;
             } else {
                 $variables = array();
                 //$options = array();
                 if ($result instanceof ViewModel) {
                     $variables = $result->getVariables();
                     $options = $result->getOptions();
                 } elseif ($result instanceof FeedDataModel) {
                     $variables = (array) $result;
                     $options = array('feed_type' => $result->getType());
                 } else {
                     if ($viewModel) {
                         $variables = $viewModel->getVariables();
                         //$options = $viewModel->getOptions();
                     }
                     if (ArrayUtils::hasStringKeys($result, true)) {
                         $variables = array_merge_recursive((array) $variables, (array) $result);
                     }
//.........这里部分代码省略.........
开发者ID:Andyyang1981,项目名称:pi,代码行数:101,代码来源:ViewStrategyListener.php


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