Exemplo n.º 1
0
    /**
     * Retrieve rendered contents of a controller action
     *
     * If the action results in a forward or redirect, returns empty string.
     *
     * @param  string $action
     * @param  string $controller
     * @param  string $module Defaults to default module
     * @param  array $params
     * @return string
     */
    public function action($action, $controller, $module = null, array $params = array())
    {
        $this->resetObjects();
        if (null === $module) {
            $module = $this->defaultModule;
        }

        // clone the view object to prevent over-writing of view variables
        $viewRendererObj = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj);

        $this->request->setParams($params)
                      ->setModuleName($module)
                      ->setControllerName($controller)
                      ->setActionName($action)
                      ->setDispatched(true);

        $this->dispatcher->dispatch($this->request, $this->response);

        // reset the viewRenderer object to it's original state
        Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj);


        if (!$this->request->isDispatched()
            || $this->response->isRedirect())
        {
            // forwards and redirects render nothing
            return '';
        }

        $return = $this->response->getBody();
        $this->resetObjects();
        return $return;
    }
Exemplo n.º 2
0
 /**
  * @param \Zend\Stdlib\ResponseInterface $r
  * @param \Zend_Controller_Response_Abstract $response
  */
 public function renderIntoResponse(Response $r, \Zend_Controller_Response_Abstract $response)
 {
     // render ZF1 response into ZF2 response
     if ($response->isException() && $response->renderExceptions()) {
         $exceptions = '';
         foreach ($response->getException() as $e) {
             $exceptions .= $e . "\n";
         }
         $body = $exceptions;
     } else {
         $body = $response->getBody();
     }
     $r->setContent($body);
     if ($r instanceof HttpResponse) {
         $r->setStatusCode($response->getHttpResponseCode());
         $r->setHeaders($this->getHeadersFromResponse($response));
         $type = $r->getHeaders()->get('Content-Type');
         if (!$type) {
             $r->getHeaders()->addHeaderLine('Content-Type', 'text/html');
         }
     }
 }
Exemplo n.º 3
0
    /**
     * Add header text
     *
     * @param Zend_Controller_Response_Abstract $response
     */
    protected function addHeader($response)
    {
        $config = Zend_Registry::get('config');
        $homepage = T_("Homepage");
        $identity = Zend_Auth::getInstance()->getIdentity();
        $loggedAs = !($identity === null) ? T_("Logged as") . " " . $identity['username'] : "";
        $menu = new USVN_Menu(USVN_MENUS_DIR, $this->getRequest(), $identity);
        $header = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
\t<head>
\t    <title>{$config->site->title}</title>
\t\t<meta http-equiv="Content-Type"\tcontent="text/html; charset=utf-8" />
\t\t<link rel="icon" href="{$config->url->base}/{$config->site->ico}" type="image/x-icon" />
\t\t<link type="text/css" rel="stylesheet" media="screen" href="{$config->url->base}/medias/usvn/stylesheets/new.css" />
\t\t<script type="text/javascript" src="{$config->url->base}/js/"></script>
\t</head>
\t<body>
\t\t<div id="usvn_page">
\t\t\t<div id="usvn_header">
\t\t\t\t<a id="usvn_logo" href="{$config->url->base}/">
\t\t\t\t\t<img src="{$config->url->base}/{$config->site->logo}" alt="{$homepage}" />
\t\t\t\t</a>
\t\t\t</div>
\t\t\t<div id="menu">
EOF;
        $header .= $this->buildMenu($menu->getTopMenu(), 'usvn_menu');
        $header .= $this->buildMenu($menu->getSubMenu(), 'usvn_submenu');
        $header .= $this->buildMenu($menu->getSubSubMenu(), 'usvn_subsubmenu');
        $header .= "</div><div id=\"usvn_content\">";
        $body = $response->getBody(true);
        $response->setBody($header);
        foreach ($body as $text) {
            $response->appendBody($text);
        }
    }