本文整理汇总了PHP中Zend\View\Model\ViewModel::getTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::getTemplate方法的具体用法?PHP ViewModel::getTemplate怎么用?PHP ViewModel::getTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ViewModel
的用法示例。
在下文中一共展示了ViewModel::getTemplate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPartialOption
public function testPartialOption()
{
$options = ['partial' => 'my/custom/partial'];
$this->view->expects($this->once())->method('partial')->with(dirname($this->viewModel->getTemplate()) . '/' . $options['partial']);
$helper = $this->helper;
$helper($this->validData(), $options);
}
示例2: createService
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var \Zend\Mvc\Application $app */
$app = $serviceLocator->get('Application');
/** @var \Zend\Mvc\Router\Http\RouteMatch $routeMatch */
$routeMatch = $app->getMvcEvent()->getRouteMatch();
if ($routeMatch->getParam('viewModel')) {
$viewModel = $serviceLocator->get($routeMatch->getParam('viewModel'));
if (!$viewModel instanceof ViewModel) {
throw new \RuntimeException('ViewModel must be instance of ' . ViewModel::class);
}
} else {
$viewModel = new ViewModel();
}
if (!$viewModel->getTemplate()) {
$template = $routeMatch->getParam('template');
if ($template) {
if (!is_string($template)) {
throw new \RuntimeException('Parameter template must be string');
}
$viewModel->setTemplate($template);
}
}
return $viewModel;
}
示例3: testSetLayoutTemplate
public function testSetLayoutTemplate()
{
$listener = new LayoutTemplateListener($this->layoutUpdater);
$layout = new ViewModel();
$this->assertEmpty($layout->getTemplate());
$event = new \Zend\Mvc\MvcEvent();
$event->setViewModel($layout);
$listener->setLayoutTemplate($event);
$this->assertEquals('2cols-left', $layout->getTemplate());
}
示例4: testLayoutCanBeInjectedWithSetter
public function testLayoutCanBeInjectedWithSetter()
{
$layout = new ViewModel();
$layout->setTemplate('layout.phtml');
$viewModel = new ViewModel();
$viewModel->setTemplate('index.phtml');
$zendView = $this->prophesize(ZendView::class);
$zendView->render(Argument::that(function ($viewModel) {
$this->assertEquals('layout.phtml', $viewModel->getTemplate());
return true;
}))->willReturn('OUTPUT');
$view = new View($zendView->reveal());
$view->setLayout($layout);
$output = $view->render($viewModel);
$this->assertEquals('OUTPUT', $output);
}
示例5: dashboardAction
public function dashboardAction()
{
$model = new ViewModel();
$model->setTemplate('core/index/dashboard');
$widgets = array();
$modules = $this->getServiceLocator()->get('ModuleManager')->getLoadedModules();
$widgets = array();
foreach ($this->config('dashboard', array_keys($modules)) as $module => $cfg) {
if (!isset($cfg['enabled']) || true !== $cfg['enabled']) {
continue;
}
foreach ($cfg['widgets'] as $captureTo => $spec) {
if (isset($spec['controller'])) {
$params = array('action' => 'dashboard');
if (isset($spec['params'])) {
$params = array_merge($params, $spec['params']);
}
$viewModel = $this->forward()->dispatch($spec['controller'], $params);
// we ignore all errors and simply continue with the error template as widget content
$response = $this->getResponse();
if (200 != $response->getStatusCode()) {
$response->setStatusCode(200);
$viewModel = array('content' => 'Error loading widget.');
}
if (!$viewModel instanceof ViewModel) {
$viewModel = new ViewModel($viewModel);
}
if ($template = $viewModel->getTemplate()) {
$viewModel->setVariable('script', $template);
}
} else {
if (isset($spec['script'])) {
$viewModel = new ViewModel(array('script' => $spec['script']));
} else {
if (isset($spec['content'])) {
$viewModel = new ViewModel(array('content' => $spec['content']));
}
}
}
$viewModel->setTemplate('core/index/dashboard-widget.phtml');
$model->addChild($viewModel, "dashboard_{$module}_{$captureTo}");
//$widgets[] = $viewModel;
}
}
//$model->setVariable('widgets', $widgets);
return $model;
}
示例6: testTemplateIsMutable
public function testTemplateIsMutable()
{
$model = new ViewModel();
$model->setTemplate('foo');
$this->assertEquals('foo', $model->getTemplate());
}
示例7: 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);
}
//.........这里部分代码省略.........
示例8: getEmailTemplate
/**
* Get email template
*
* @return string
*/
public function getEmailTemplate()
{
return $this->viewModel->getTemplate();
}