本文整理汇总了PHP中Zend\View\ViewEvent::setRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::setRequest方法的具体用法?PHP ViewEvent::setRequest怎么用?PHP ViewEvent::setRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::setRequest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReturnsNullWhenCannotSelectRenderer
public function testReturnsNullWhenCannotSelectRenderer()
{
$model = new ViewModel();
$request = new HttpRequest();
$this->event->setModel($model);
$this->event->setRequest($request);
$this->assertNull($this->strategy->selectRenderer($this->event));
}
示例2: testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent
public function testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent()
{
$event = new ViewEvent();
$event->setName(ViewEvent::EVENT_RENDERER);
$event->setModel(new ApiBlueprintModel(array()));
$event->setRequest(new HttpRequest());
$renderer = $this->strategy->selectRenderer($event);
$this->assertSame($this->renderer, $renderer);
return $event;
}
开发者ID:BreiteSeite,项目名称:zf-apigility-documentation-apiblueprint,代码行数:10,代码来源:ApiBlueprintViewStrategyTest.php
示例3: selectRenderer
/**
* Select the ViewRenderer
*
* @param ViewEvent $e
* @return ViewRenderer
*/
public function selectRenderer(ViewEvent $e)
{
if ($this->enhanced == false) {
$request = $e->getRequest();
$model = $e->getModel();
// this happens if the route is not matched properly
if (!$request instanceof Request) {
$request = new Request();
$e->setRequest($request);
}
// add base elements
$model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
$model->setVariable("request", $request);
$model->setVariable("config", Registry::getInstance());
// add navigation
$nav = new Navigation($e);
$model->setVariable("navbar", $nav->getNavbar());
// show internal xml
if ($request->getParam('format') == 'xerxes') {
$this->renderer->setFormat('xml');
} else {
// determine which view script to use
if ($e->getResponse()->getStatusCode() != 200) {
$model->setVariable("display_exceptions", true);
$model->setTemplate('error/index.phtml');
} else {
// determine which view script to use
$script = $request->getControllerMap()->getView($request->getParam('format'));
// test view chosen
// header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit;
$model->setTemplate($script);
}
// render it
$display_as = "html";
if ($request->getParam('format') == 'json') {
$display_as = "json";
}
$this->renderer->setFormat($display_as);
}
$this->enhanced = true;
}
return $this->renderer;
}
示例4: getEvent
/**
* Create and return ViewEvent used by render()
*
* @return ViewEvent
*/
protected function getEvent()
{
$event = new ViewEvent();
$event->setTarget($this);
if (null !== ($request = $this->getRequest())) {
$event->setRequest($request);
}
if (null !== ($response = $this->getResponse())) {
$event->setResponse($response);
}
return $event;
}
示例5: selectRenderer
/**
* Select the ViewRenderer
*
* @param ViewEvent $e
* @return ViewRenderer
*/
public function selectRenderer(ViewEvent $e)
{
if ($this->enhanced == false) {
$request = $e->getRequest();
$model = $e->getModel();
$registry = Registry::getInstance();
// this happens if the route is not matched properly
if (!$request instanceof Request) {
$request = new Request();
$e->setRequest($request);
}
// add base elements
$model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl());
$model->setVariable("request", $request);
$model->setVariable("config", $registry);
// add navigation
$nav = new Navigation($e);
$model->setVariable("navbar", $nav->getNavbar());
### flatten model
// @todo this seems really hacky, but our view renderer
// has no notion of children, so this makes our lives easier
foreach ($model->getChildren() as $child) {
// template specified
$model->setTemplate($child->getTemplate());
// terminate this?
$model->setTerminal($child->terminate());
// options
$options = $child->getOptions();
foreach ($options as $id => $value) {
$model->setOption($id, $value);
}
// variables
$child_variables = $child->getVariables();
foreach ($child_variables as $id => $value) {
$model->setVariable($id, $value);
}
}
// show internal xml
if ($request->getParam('format') == 'xerxes') {
$this->renderer->setFormat('xml');
} else {
// error
if ($e->getResponse()->getStatusCode() != 200) {
$display_excpetions = false;
if ($_SERVER['APPLICATION_ENV'] == 'development' || $registry->getConfig('DISPLAY_ERRORS', false, false) == true) {
$display_excpetions = true;
}
$model->setVariable("display_exceptions", $display_excpetions);
if ($e->getResponse()->getStatusCode() == 404) {
$model->setTemplate('error/404.phtml');
} else {
$model->setTemplate('error/index.phtml');
}
} elseif (!strstr($model->getTemplate(), '.')) {
$script = $request->getControllerMap()->getView($request->getParam('format'));
// test view chosen
// header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit;
$model->setTemplate($script);
}
// render it
$display_as = "html";
if ($request->getParam('format') == 'json') {
$display_as = "json";
}
$this->renderer->setFormat($display_as);
}
$this->enhanced = true;
}
return $this->renderer;
}