Esempio n. 1
0
 /**
  * @return mixed
  */
 public function notFoundByRequestedCriteria($criteriaErrors)
 {
     $zendResponse = $this->mvcEvent->getResponse();
     $zendResponse->setStatusCode(404);
     $this->viewModel->setVariable('message', 'The requested resource was not found by requested criteria');
     $this->viewModel->setTemplate('error/404');
     $this->mvcEvent->setResult($this->viewModel);
     return $this->viewModel;
 }
Esempio n. 2
0
 /**
  * assign wrapper template to block
  *
  * @param ModelInterface $block
  * @param array|string $options
  */
 protected function wrapBlock(ModelInterface $block, $options)
 {
     $attributes = $options;
     if (is_string($options)) {
         $wrapperTemplate = $options;
         $attributes = [];
     } elseif (is_array($options) && !isset($options['template'])) {
         $wrapperTemplate = self::WRAPPER_DEFAULT;
     } else {
         $wrapperTemplate = $options['template'];
         unset($attributes['template']);
     }
     if (isset($options['tag'])) {
         $block->setVariable('wrapperTag', $options['tag']);
         unset($attributes['tag']);
     }
     $originalTemplate = $block->getTemplate();
     $block->setOption('is_wrapped', true);
     $block->setTemplate($wrapperTemplate);
     $block->setVariable('wrapperAttributes', $attributes);
     $block->setVariable('originalTemplate', $originalTemplate);
 }
 /**
  * Populate the view model returned by the AcceptableViewModelSelector from the result
  *
  * If the result is a ViewModel, we "re-cast" it by copying over all
  * values/settings/etc from the original.
  *
  * If the result is an array, we pass those values as the view model variables.
  *
  * @param  array|ViewModel $result
  * @param  ViewModelInterface $viewModel
  * @param  MvcEvent $e
  */
 protected function populateViewModel($result, ViewModelInterface $viewModel, MvcEvent $e)
 {
     if ($result instanceof ViewModel) {
         // "Re-cast" content-negotiation view models to the view model type
         // selected by the AcceptableViewModelSelector
         $viewModel->setVariables($result->getVariables());
         $viewModel->setTemplate($result->getTemplate());
         $viewModel->setOptions($result->getOptions());
         $viewModel->setCaptureTo($result->captureTo());
         $viewModel->setTerminal($result->terminate());
         $viewModel->setAppend($result->isAppend());
         if ($result->hasChildren()) {
             foreach ($result->getChildren() as $child) {
                 $viewModel->addChild($child);
             }
         }
         $e->setResult($viewModel);
         return;
     }
     // At this point, the result is an array; use it to populate the view
     // model variables
     $viewModel->setVariables($result);
     $e->setResult($viewModel);
 }
 /**
  * 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;
 }