本文整理汇总了PHP中Zend\View\Model\ViewModel::getVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::getVariables方法的具体用法?PHP ViewModel::getVariables怎么用?PHP ViewModel::getVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\Model\ViewModel
的用法示例。
在下文中一共展示了ViewModel::getVariables方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction()
{
try {
$object = $this->getUuidManager()->getUuid($this->params('uuid'), true);
} catch (NotFoundException $e) {
$this->getResponse()->setStatusCode(404);
return false;
}
$normalized = $this->getNormalizer()->normalize($object);
$routeName = $normalized->getRouteName();
$routeParams = $normalized->getRouteParams();
$type = $normalized->getType();
$url = $this->url()->fromRoute($routeName, $routeParams, null, null, false);
if (!$this->getRequest()->isXmlHttpRequest()) {
$url = $this->url()->fromRoute($routeName, $routeParams);
$response = $this->redirect()->toUrl($url);
$this->getResponse()->setStatusCode(301);
return $response;
}
$router = $this->getServiceLocator()->get('Router');
$request = new Request();
$request->setMethod(Request::METHOD_GET);
$request->setUri($url);
$routeMatch = $router->match($request);
if (!$routeMatch) {
throw new RuntimeException(sprintf('Could not match a route for `%s`', $url));
}
$params = array_merge($routeMatch->getParams(), ['forwarded' => true, 'isXmlHttpRequest' => true]);
$controller = $params['controller'];
$response = $this->forward()->dispatch($controller, $params);
// TODO: Do me a favor and remove this piece of cr*p with something that doesn't hack the whole thing
if ($response instanceof JsonModel) {
$response = new ViewModel(['data' => $response->getVariables()]);
$response->setTemplate('normalizer/json');
}
$view = new ViewModel(['id' => $object->getId(), 'type' => $type, 'url' => $url, '__disableTemplateDebugger' => true]);
$view->addChild($response, 'response');
$view->setTemplate('normalizer/ref');
$view->setTerminal(true);
return $view;
}
示例2: testIfViewModelComposesVariablesInstanceThenRendererUsesIt
/**
* @group view-model
*/
public function testIfViewModelComposesVariablesInstanceThenRendererUsesIt()
{
$model = new ViewModel();
$model->setTemplate('template');
$vars = $model->getVariables();
$vars['foo'] = 'BAR-BAZ-BAT';
$resolver = new TemplateMapResolver(array('template' => __DIR__ . '/_templates/view-model-variables.phtml'));
$this->renderer->setResolver($resolver);
$test = $this->renderer->render($model);
$this->assertContains('BAR-BAZ-BAT', $test);
}
示例3: testPropertyOverloadingAllowsWritingPropertiesAfterSetVariablesHasBeenCalled
public function testPropertyOverloadingAllowsWritingPropertiesAfterSetVariablesHasBeenCalled()
{
$model = new ViewModel();
$model->setVariables(array('foo' => 'bar'));
$model->bar = 'baz';
$this->assertTrue(isset($model->bar));
$this->assertEquals('baz', $model->bar);
$variables = $model->getVariables();
$this->assertTrue(isset($variables['bar']));
$this->assertEquals('baz', $variables['bar']);
}
示例4: testPropertyOverloadingGivesAccessToProperties
public function testPropertyOverloadingGivesAccessToProperties()
{
$model = new ViewModel();
$variables = $model->getVariables();
$model->foo = 'bar';
$this->assertTrue(isset($model->foo));
$this->assertEquals('bar', $variables['foo']);
$this->assertEquals('bar', $model->foo);
unset($model->foo);
$this->assertFalse(isset($model->foo));
$this->assertFalse(isset($variables['foo']));
}
示例5: _setStrictVars
/**
* Set strict vars on a view model recursively
*
* @param \Zend\View\Model\ViewModel $model
*/
protected function _setStrictVars(\Zend\View\Model\ViewModel $model)
{
$vars = $model->getVariables();
if (!$vars instanceof \Zend\View\Variables) {
$vars = new \Zend\View\Variables($vars);
}
$vars->setStrictVars(true);
$model->setVariables($vars, true);
foreach ($model->getChildren() as $child) {
$this->_setStrictVars($child);
}
}