Pop\Mvc\View::render PHP Метод

render() публичный Метод

Render the view.
public render ( boolean $ret = false ) : mixed
$ret boolean
Результат mixed
    public function render($ret = false)
    {
        if (null === $this->templateFile && null === $this->templateString) {
            throw new Exception('A template asset has not been assigned.');
        }
        if (null !== $this->templateFile) {
            $this->renderTemplateFile();
        } else {
            $this->renderTemplateString();
        }
        if ($ret) {
            return $this->output;
        } else {
            echo $this->output;
        }
    }

Usage Example

Пример #1
0
 /**
  * Finalize the request and send the response.
  *
  * @param  int   $code
  * @param  array $headers
  * @throws \Pop\Mvc\Exception
  * @return void
  */
 public function send($code = 200, array $headers = null)
 {
     if (null === $this->view) {
         throw new Exception('The view object is not defined.');
     }
     if (!$this->view instanceof View) {
         throw new Exception('The view object is not an instance of Pop\\Mvc\\View.');
     }
     if (null !== $this->project->logger()) {
         $this->project->log("Response [" . $code . "]", time());
     }
     $this->response->setCode($code);
     if (null !== $headers) {
         foreach ($headers as $name => $value) {
             $this->response->setHeader($name, $value);
         }
     }
     // Trigger any dispatch events, then send the response
     if (null !== $this->project->getEventManager()->get('dispatch')) {
         $this->project->log('[Event] Dispatch', time(), \Pop\Log\Logger::NOTICE);
     }
     $this->project->getEventManager()->trigger('dispatch', array('controller' => $this));
     $this->response->setBody($this->view->render(true));
     if (null !== $this->project->getEventManager()->get('dispatch.send')) {
         $this->project->log('[Event] Dispatch Send', time(), \Pop\Log\Logger::NOTICE);
     }
     $this->project->getEventManager()->trigger('dispatch.send', array('controller' => $this));
     $this->response->send();
 }