本文整理汇总了PHP中Zend\View\Model\ViewModel::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::setOption方法的具体用法?PHP ViewModel::setOption怎么用?PHP ViewModel::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ViewModel
的用法示例。
在下文中一共展示了ViewModel::setOption方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInjectTagsHeader
public function testInjectTagsHeader()
{
$tag = InjectTagsHeaderListener::OPTION_CACHE_TAGS;
$event = new MvcEvent();
$response = new Response();
$event->setResponse($response);
$layout = new ViewModel();
$child1 = new ViewModel();
$child1->setOption($tag, ['tag1', 'tag2']);
$layout->addChild($child1);
$child2 = new ViewModel();
$child21 = new ViewModel();
$child21->setOption($tag, ['tag3', null]);
$child2->addChild($child21);
$layout->addChild($child2);
$child3 = new ViewModel();
$child3->setOption('esi', ['ttl' => 120]);
$child3->setOption($tag, 'tag4');
$layout->addChild($child3);
$event->setViewModel($layout);
$this->listener->injectTagsHeader($event);
$this->assertSame(['tag1', 'tag2', 'tag3'], $this->listener->getCacheTags());
$headers = $response->getHeaders();
$this->assertEquals('tag1,tag2,tag3', $headers->get(VarnishService::VARNISH_HEADER_TAGS)->getFieldValue());
}
示例2: 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());
}
示例3: renderView
public function renderView($page, array $data)
{
$model = new ViewModel();
$model->setTemplate("mailer/{$page}.phtml");
$model->setOption('has_parent', true);
$model->setVariables($data);
return $this->view->render($model);
}
示例4: testCastsViewModelToFeedModelUsingFeedTypeOptionProvided
public function testCastsViewModelToFeedModelUsingFeedTypeOptionProvided()
{
$model = new ViewModel($this->getFeedData('atom'));
$model->setOption('feed_type', 'atom');
$xml = $this->renderer->render($model);
$this->assertContains('<' . '?xml', $xml);
$this->assertContains('atom', $xml);
}
示例5: __invoke
public function __invoke($revisionEntity)
{
$view = $this->getServiceLocator()->getServiceLocator()->get('View');
$model = new ViewModel();
$model->setTemplate('soliant-entity-audit/helper/revision-entity-link.phtml');
$model->setVariable('revisionEntity', $revisionEntity);
$model->setOption('has_parent', true);
return $view->render($model);
}
示例6: testMarkupContainsCommentsWithDebugInfo
public function testMarkupContainsCommentsWithDebugInfo()
{
$block = new ViewModel();
$block->setOption('block_id', 'the.block');
$viewModelHelper = new ModelHelper();
$viewModelHelper->setCurrent($block);
$filter = new DebugFilter($viewModelHelper);
$html = '<div></div>';
$filteredHtml = $filter->filter($html);
$this->assertContains('<!--[the.block]', $filteredHtml);
}
示例7: testParentBlockIsAddedAsOption
public function testParentBlockIsAddedAsOption()
{
$parent = new ViewModel();
$child = new ViewModel();
$child->setOption('block_id', 'child');
$child2 = new ViewModel();
$child2->setOption('block_id', 'child2');
$child->addChild($child2);
$parent->addChild($child);
$this->layout->setRoot($parent);
$this->layout->load();
$childBlock = $this->layout->getBlock('child');
$this->assertSame($parent, $childBlock->getOption('parent_block'));
$child2Block = $this->layout->getBlock('child2');
$this->assertSame($childBlock, $child2Block->getOption('parent_block'));
$this->assertSame($parent, $child2Block->getOption('parent_block')->getOption('parent_block'));
}
示例8: testCanOverwriteOptionsSingly
public function testCanOverwriteOptionsSingly()
{
$model = new ViewModel(array(), array('foo' => 'bar'));
$model->setOption('foo', 'baz');
$this->assertEquals(array('foo' => 'baz'), $model->getOptions());
}
示例9: testBypassesRenderingIfResultIsAResponse
public function testBypassesRenderingIfResultIsAResponse()
{
$renderer = new TestAsset\DumbStrategy();
$this->view->addRenderingStrategy(function ($e) use($renderer) {
return $renderer;
}, 100);
$model = new ViewModel(array('foo' => 'bar'));
$model->setOption('template', 'content');
$this->event->setViewModel($model);
$this->event->setResult($this->response);
$result = $this->strategy->render($this->event);
$this->assertSame($this->response, $result);
}
示例10: renderAction
/**
* Render an action from a controller and render it's associated template
* @param string $expr
* @param array $attributes
* @param array $options
* @return string
*/
public function renderAction($expr, array $attributes, array $options)
{
ArgValidator::assert($expr, 'string');
$serviceManager = Module::getServiceManager();
$application = $serviceManager->get('Application');
//parse the name of the controller, action and template directory that should be used
if (strpos($expr, '/') > 0) {
list($controllerName, $actionName) = explode('/', $expr);
$templateDir = $controllerName . '/';
} else {
list($moduleName, $controllerName, $actionName) = explode(':', $expr);
$actionName = lcfirst($actionName);
$actionName = strtolower(preg_replace('/([A-Z])/', '-$1', $actionName));
$templateDir = lcfirst($moduleName) . '/' . lcfirst($controllerName) . '/';
$controllerName = $moduleName . '\\Controller\\' . $controllerName . 'Controller';
}
//instantiate the controller based on the given name
$controller = $serviceManager->get('ControllerLoader')->get($controllerName);
//clone the MvcEvent and route and update them with the provided parameters
$event = $application->getMvcEvent();
$routeMatch = clone $event->getRouteMatch();
$event = clone $event;
foreach ($attributes as $key => $value) {
$routeMatch->setParam($key, $value);
}
$event->setRouteMatch($routeMatch);
//inject the new event into the controller
if ($controller instanceof InjectApplicationEventInterface) {
$controller->setEvent($event);
}
//test if the action exists in the controller and change it to not-found if missing
$method = AbstractActionController::getMethodFromAction($actionName);
if (!method_exists($controller, $method)) {
$method = 'notFoundAction';
$actionName = 'not-found';
}
//call the method on the controller
$response = $controller->{$method}();
//if the result is an instance of the Response class return it
if ($response instanceof Response) {
return $response->getBody();
}
//if the response is an instance of ViewModel then render that one
if ($response instanceof ModelInterface) {
$viewModel = $response;
} elseif ($response === null || is_array($response) || $response instanceof \ArrayAccess || $response instanceof \Traversable) {
$viewModel = new ViewModel($response);
$viewModel->setTemplate($templateDir . $actionName);
} else {
return '';
}
$viewModel->terminate();
$viewModel->setOption('has_parent', true);
$view = $serviceManager->get('Zend\\View\\View');
$output = $view->render($viewModel);
return $output;
}
示例11: testGetCaptureToDefault
public function testGetCaptureToDefault()
{
$viewModel = new ViewModel();
$viewModel->setOption('parent', 'some.parent');
$layout = new TestLayout($this->blockFactory, $this->updaterMock);
$this->assertEquals(['some.parent', 'content'], $layout->getCaptureTo($viewModel));
}
示例12: testInjectEsi
public function testInjectEsi()
{
$block = new ViewModel();
$block->setOption('esi', ['ttl' => 120]);
$block->setTemplate('default');
$event = new Event();
$event->setParam('block', $block);
$this->listener->determineEsiProcessing($this->mvcEvent);
$this->listener->injectEsi($event);
$this->assertEquals('default', $block->getTemplate());
$this->listener->setCanUseEsi(true);
$this->listener->injectEsi($event);
$this->assertEquals(InjectCacheHeaderListener::ESI_TEMPLATE, $block->getTemplate());
}