本文整理汇总了PHP中Zend\View\Model\ModelInterface::setVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelInterface::setVariable方法的具体用法?PHP ModelInterface::setVariable怎么用?PHP ModelInterface::setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ModelInterface
的用法示例。
在下文中一共展示了ModelInterface::setVariable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: notFoundByRequestedCriteria
/**
* @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;
}
示例2: renderChildren
/**
*
* @param ModelInterface $model
*/
protected function renderChildren(ModelInterface $model)
{
foreach ($model->getChildren() as $child) {
$result = $this->render($child);
$capture = $child->captureTo();
if (!empty($capture)) {
if ($child->isAppend()) {
$oldResult = $model->{$capture};
$model->setVariable($capture, $oldResult . $result);
} else {
$model->setVariable($capture, $result);
}
}
}
}
示例3: renderChildren
/**
* @param \Zend\View\Model\ModelInterface $oViewModel
* @throws \DomainException
* @return \BoilerAppMessenger\Media\Mail\MailMessageRenderer
*/
protected function renderChildren(\Zend\View\Model\ModelInterface $oViewModel)
{
foreach ($oViewModel as $oChild) {
if ($oChild->terminate()) {
throw new \DomainException('Inconsistent state; child view model is marked as terminal');
}
$oChild->setOption('has_parent', true);
$sResult = $this->renderChildren($oChild)->render($oChild);
$oChild->setOption('has_parent', null);
$sCapture = $oChild->captureTo();
if (!empty($sCapture)) {
$oViewModel->setVariable($sCapture, $oChild->isAppend() ? $oViewModel->{$sCapture} . $sResult : $sResult);
}
}
return $this;
}
示例4: renderChildren
/**
* Loop through children, rendering each
*
* @param Model $model
* @throws Exception\DomainException
* @return void
*/
protected function renderChildren(Model $model)
{
foreach ($model as $child) {
if ($child->terminate()) {
throw new Exception\DomainException('Inconsistent state; child view model is marked as terminal');
}
$child->setOption('has_parent', true);
$result = $this->render($child);
$child->setOption('has_parent', null);
$capture = $child->captureTo();
if (!empty($capture)) {
if ($child->isAppend()) {
$oldResult = $model->{$capture};
$model->setVariable($capture, $oldResult . $result);
} else {
$model->setVariable($capture, $result);
}
}
}
}
示例5: injectChildren
/**
* Inject discovered child model values into parent model
*
* @todo detect collisions and decide whether to append and/or aggregate?
* @param Model $model
* @param array $children
*/
protected function injectChildren(Model $model, array $children)
{
foreach ($children as $child => $value) {
// TODO detect collisions and decide whether to append and/or aggregate?
$model->setVariable($child, $value);
}
}
示例6: renderModel
/**
* Do a recursive, depth-first rendering of a view model.
*
* @param ModelInterface $model
* @param RendererInterface $renderer
* @return string
* @throws Exception\RenderingException if it encounters a terminal child.
*/
private function renderModel(ModelInterface $model, RendererInterface $renderer)
{
foreach ($model as $child) {
if ($child->terminate()) {
throw new Exception\RenderingException('Cannot render; encountered a child marked terminal');
}
$capture = $child->captureTo();
if (empty($capture)) {
continue;
}
$result = $this->renderModel($child, $renderer);
if ($child->isAppend()) {
$oldResult = $model->{$capture};
$model->setVariable($capture, $oldResult . $result);
continue;
}
$model->setVariable($capture, $result);
}
return $renderer->render($model);
}
示例7: wrapBlock
/**
* 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);
}
示例8: determineAnonymousBlockId
/**
*
* @param ViewModel $block
* @return string
*/
protected function determineAnonymousBlockId(ModelInterface $block)
{
$blockId = $block->getVariable(self::BLOCK_ID_VAR);
if (!$blockId) {
$blockId = sprintf(self::ANONYMOUS_ID_PATTERN, $block->captureTo(), self::$anonymousSuffix++);
$block->setVariable(self::BLOCK_ID_VAR, $blockId);
}
return $blockId;
}
示例9: configure
/**
* @inheritDoc
*/
public function configure(ModelInterface $block, array $specs)
{
$specs = $this->prepareOptions($specs);
foreach ($this->getOption('options', $specs) as $name => $option) {
$block->setOption($name, $option);
}
foreach ($this->getOption('variables', $specs) as $name => $variable) {
$block->setVariable($name, $variable);
}
foreach ($this->getOption('actions', $specs) as $params) {
if (isset($params['method'])) {
$method = (string) $params['method'];
if (method_exists($block, $method)) {
$this->invokeArgs($block, $method, $params);
} else {
throw new BadMethodCallException(sprintf('Call to undefined block method %s::%s()', get_class($block), $method));
}
}
}
if (!$block->getTemplate() && ($template = $this->getOption('template', $specs))) {
$block->setTemplate($template);
}
$block->setCaptureTo($this->getOption('capture_to', $specs));
$block->setAppend($this->getOption('append', $specs));
$block->setVariable('block', $block);
if ($block instanceof BlockInterface) {
$block->setView($this->container->get('ViewRenderer'));
$block->setRequest($this->container->get('Request'));
}
$results = $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, ['block' => $block, 'specs' => $specs], function ($result) {
return $result instanceof ModelInterface;
});
if ($results->stopped()) {
$block = $results->last();
}
return $block;
}
示例10: addVariable
/**
* Add a variable to the View Model
*
* @param string $name
* @param mixed $value
*/
protected function addVariable($name, $value)
{
$this->model->setVariable($name, $value);
}
示例11: attachToView
/**
* Add acl to the view model
*
* @param ModelInterface $viewModel
*
* @return mixed
*/
public function attachToView(ModelInterface $viewModel)
{
$viewModel->setVariable('acl', $this->getAcl());
return $this;
}
示例12: prepareLayout
/**
* Prepare the layout, if any.
*
* Injects the view model in the layout view model, if present.
*
* If the view model contains a non-empty 'layout' variable, that value
* will be used to seed a layout view model, if:
*
* - it is a string layout template name
* - it is a ModelInterface instance
*
* If a layout is discovered in this way, it will override the one set in
* the constructor, if any.
*
* Returns the provided $viewModel unchanged if no layout is discovered;
* otherwise, a view model representing the layout, with the provided
* view model as a child, is returned.
*
* @param ModelInterface $viewModel
* @return ModelInterface
*/
private function prepareLayout(ModelInterface $viewModel)
{
$layout = $this->layout ? clone $this->layout : null;
$providedLayout = $viewModel->getVariable('layout', false);
if (is_string($providedLayout) && !empty($providedLayout)) {
$layout = new ViewModel();
$layout->setTemplate($providedLayout);
$viewModel->setVariable('layout', null);
} elseif ($providedLayout instanceof ModelInterface) {
$layout = $providedLayout;
$viewModel->setVariable('layout', null);
}
if ($layout) {
$layout->addChild($viewModel);
$viewModel = $layout;
}
return $viewModel;
}