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


PHP ModelInterface::getVariables方法代码示例

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


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

示例1: render

 /**
  * Renders values as JSON
  *
  * @todo   Determine what use case exists for accepting only $nameOrModel
  * @param  string|Model $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values Values to use during rendering
  * @throws Exception\InvalidArgumentException
  * @return string The script output.
  */
 public function render($nameOrModel, $values = null)
 {
     if ($nameOrModel instanceof Model) {
         // Use case 1: View Model provided
         // Non-FeedModel: cast to FeedModel
         if (!$nameOrModel instanceof FeedModel) {
             $vars = $nameOrModel->getVariables();
             $options = $nameOrModel->getOptions();
             $type = $this->getFeedType();
             if (isset($options['feed_type'])) {
                 $type = $options['feed_type'];
             } else {
                 $this->setFeedType($type);
             }
             $nameOrModel = new FeedModel($vars, array('feed_type' => $type));
         }
     } elseif (is_string($nameOrModel)) {
         // Use case 2: string $nameOrModel + array|Traversable|Feed $values
         $nameOrModel = new FeedModel($values, (array) $nameOrModel);
     } else {
         // Use case 3: failure
         throw new Exception\InvalidArgumentException(sprintf('%s expects a ViewModel or a string feed type as the first argument; received "%s"', __METHOD__, is_object($nameOrModel) ? get_class($nameOrModel) : gettype($nameOrModel)));
     }
     // Get feed and type
     $feed = $nameOrModel->getFeed();
     $type = $nameOrModel->getFeedType();
     if (!$type) {
         $type = $this->getFeedType();
     } else {
         $this->setFeedType($type);
     }
     // Render feed
     return $feed->export($type);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:43,代码来源:FeedRenderer.php

示例2: render

 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values      Values to use during rendering
  * @return string The script output.
  * @throws \LogicException
  */
 public function render($nameOrModel, $values = null)
 {
     $name = $nameOrModel;
     if ($nameOrModel instanceof ModelInterface) {
         $name = $this->resolver->resolve($nameOrModel->getTemplate(), $this);
         $values = (array) $nameOrModel->getVariables();
     }
     if (array_key_exists('helper', $values)) {
         throw new \LogicException('Variable $helper is reserved for Zend helpers and can\'t be passed to view.');
     }
     $values['helper'] = $this->helpers;
     return $this->engine->renderToString($name, $values);
 }
开发者ID:halaxa,项目名称:zf2-latte,代码行数:21,代码来源:LatteRenderer.php

示例3: recurseModel

 /**
  * Retrieve values from a model and recurse its children to build a data structure
  *
  * @param  Model $model
  * @param  bool $mergeWithVariables Whether or not to merge children with
  *         the variables of the $model
  * @return array
  */
 protected function recurseModel(Model $model, $mergeWithVariables = true)
 {
     $values = [];
     if ($mergeWithVariables) {
         $values = $model->getVariables();
     }
     if ($values instanceof Traversable) {
         $values = ArrayUtils::iteratorToArray($values);
     }
     if (!$model->hasChildren()) {
         return $values;
     }
     $mergeChildren = $this->mergeUnnamedChildren();
     foreach ($model as $child) {
         $captureTo = $child->captureTo();
         if (!$captureTo && !$mergeChildren) {
             // We don't want to do anything with this child
             continue;
         }
         $childValues = $this->recurseModel($child);
         if ($captureTo) {
             // Capturing to a specific key
             // TODO please complete if append is true. must change old
             // value to array and append to array?
             $values[$captureTo] = $childValues;
         } elseif ($mergeChildren) {
             // Merging values with parent
             $values = array_replace_recursive($values, $childValues);
         }
     }
     return $values;
 }
开发者ID:CHRISTOPHERVANDOMME,项目名称:zf2complet,代码行数:40,代码来源:JsonRenderer.php

示例4: render

 /**
  * Recursively processes all ViewModels and returns output.
  *
  * @param  string|ModelInterface   $model        A ViewModel instance.
  * @param  null|array|\Traversable $values       Values to use when rendering. If none
  *                                               provided, uses those in the composed
  *                                               variables container.
  * @return string Console output.
  */
 public function render($model, $values = null)
 {
     if (!$model instanceof ModelInterface) {
         return '';
     }
     $result = '';
     $options = $model->getOptions();
     foreach ($options as $setting => $value) {
         $method = 'set' . $setting;
         if (method_exists($this, $method)) {
             $this->{$method}($value);
         }
         unset($method, $setting, $value);
     }
     unset($options);
     $values = $model->getVariables();
     if (isset($values['result'])) {
         // filter and append the result
         $result .= $this->getFilterChain()->filter($values['result']);
     }
     if ($model->hasChildren()) {
         // recursively render all children
         foreach ($model->getChildren() as $child) {
             $result .= $this->render($child, $values);
         }
     }
     return $result;
 }
开发者ID:Flesh192,项目名称:magento,代码行数:37,代码来源:ConsoleRenderer.php

示例5: render

 /**
  * Recursively processes all ViewModels and returns output.
  *
  * @param string|ModelInterface $model A ViewModel instance.
  * @param null|array|\Traversable $values Values to use when rendering. If
  *     none provided, uses those in the composed variables container.
  * @return string Console output.
  */
 public function render($model, $values = null)
 {
     $result = '';
     if (!$model instanceof ModelInterface) {
         // View model is required by this renderer
         return $result;
     }
     // If option keys match setters, pass values to those methods.
     foreach ($model->getOptions() as $setting => $value) {
         $method = 'set' . $setting;
         if (method_exists($this, $method)) {
             $this->{$method}($value);
         }
     }
     // Render children first
     if ($model->hasChildren()) {
         // recursively render all children
         foreach ($model->getChildren() as $child) {
             $result .= $this->render($child, $values);
         }
     }
     // Render the result, if present.
     $values = $model->getVariables();
     if (isset($values['result']) && !isset($this->filterChain)) {
         // append the result verbatim
         $result .= $values['result'];
     }
     if (isset($values['result']) && isset($this->filterChain)) {
         // filter and append the result
         $result .= $this->getFilterChain()->filter($values['result']);
     }
     return $result;
 }
开发者ID:zendframework,项目名称:zend-mvc-console,代码行数:41,代码来源:Renderer.php

示例6: mergeViewModel

 /**
  * Merge global/template parameters with provided view model.
  *
  * @param string $name Template name.
  * @param ModelInterface $model
  * @return ModelInterface
  */
 private function mergeViewModel($name, ModelInterface $model)
 {
     $params = $this->mergeParams($name, $model->getVariables());
     $model->setVariables($params);
     $model->setTemplate($name);
     return $model;
 }
开发者ID:fabiocarneiro,项目名称:zend-expressive-zendviewrenderer,代码行数:14,代码来源:ZendViewRenderer.php

示例7: render

 /**
  * @param  string|ModelInterface   $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values      Values to use during rendering
  * @return string                  The script output.
  */
 public function render($nameOrModel, $values = null)
 {
     $result = $this->negotiator->negotiate($nameOrModel->getVariables(), $nameOrModel->getAccept());
     return $result;
 }
开发者ID:bedrest,项目名称:framework-zendframework2,代码行数:10,代码来源:ContentNegotiationRenderer.php


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