public function render($template) { $response = parent::render('header.php'); $response .= parent::render($template); $response .= parent::render('footer.php'); return $response; }
/** * Render template * @var string Template to be rendered (optional) */ public function render($template = '') { $template = is_string($template) ? $template . '.php' : null; if ($template) { $this->appendData(array('global' => $this->global)); $content = parent::render($template); } else { $content = ''; } // make sure buffers flushed ob_end_flush(); ob_flush(); ob_start(); extract(array('content' => $content, 'global' => $this->global)); if ($this->layout) { $layoutPath = $this->getTemplatesDirectory() . '/' . ltrim($this->layout, '/'); if (!file_exists($layoutPath)) { throw new RuntimeException('View cannot render layout `' . $layoutPath); } require $layoutPath; } else { echo $content; } return ob_get_clean(); //echo "render"; }
/** * Render a template * * Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR * callable to render a template whose output is appended to the * current HTTP response body. How the template is rendered is * delegated to the current View. * * @param string $template The name of the template passed into the View::render method * @param array $data Associative array of data made available to the View * @param int $status The HTTP response status code to use (Optional) * @return void */ public function render($template, $data = array(), $status = null) { if (!is_null($status)) { $this->response->status($status); } $this->view->setTemplatesDirectory($this->config('templates.path')); $this->view->appendData($data); $this->view->display($template); }
/** * Run the Slim application * * This method is the "meat and potatoes" of Slim and should be the last * method called. This fires up Slim, invokes the Route that matches * the current request, and returns the response to the client. * * This method will invoke the Not Found handler if no matching * routes are found. * * This method will also catch any unexpected Exceptions thrown by this * application; the Exceptions will be logged to this application's log * and rethrown to the global Exception handler. * * @return void */ public function run() { try { $this->applyHook('slim.before'); ob_start(); $this->applyHook('slim.before.router'); $dispatched = false; foreach ($this->router->getMatchedRoutes() as $route) { try { $this->applyHook('slim.before.dispatch'); $dispatched = $route->dispatch(); $this->applyHook('slim.after.dispatch'); if ($dispatched) { break; } } catch (Slim_Exception_Pass $e) { continue; } } if (!$dispatched) { $this->notFound(); } $this->response()->write(ob_get_clean()); $this->applyHook('slim.after.router'); $this->view->getData('flash')->save(); session_write_close(); $this->response->send(); $this->applyHook('slim.after'); } catch (Slim_Exception_RequestSlash $e) { try { $this->redirect($this->request->getRootUri() . $this->request->getResourceUri() . '/', 301); } catch (Slim_Exception_Stop $e2) { //Ignore Slim_Exception_Stop and exit application context } } catch (Slim_Exception_Stop $e) { //Exit application context } catch (Exception $e) { $this->getLog()->error($e); try { if ($this->config('debug') === true) { $this->halt(500, self::generateErrorMarkup($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString())); } else { $this->error($e); } } catch (Slim_Exception_Stop $e2) { //Ignore Slim_Exception_Stop and exit application context } } }
/** * Run the Slim application * * This method is the "meat and potatoes" of Slim and should be the last * method called. This fires up Slim, invokes the Route that matches * the current request, and returns the response to the client. * * This method will invoke the Not Found handler if no matching * routes are found. * * This method will also catch any unexpected Exceptions thrown by this * application; the Exceptions will be logged to this application's log * and rethrown to the global Exception handler. * * @return void */ public function run() { try { try { $this->applyHook('slim.before'); ob_start(); $this->applyHook('slim.before.router'); $dispatched = false; $httpMethod = $this->request()->getMethod(); $httpMethodsAllowed = array(); foreach ($this->router as $route) { if ($route->supportsHttpMethod($httpMethod)) { try { $this->applyHook('slim.before.dispatch'); $dispatched = $route->dispatch(); $this->applyHook('slim.after.dispatch'); if ($dispatched) { break; } } catch (Slim_Exception_Pass $e) { continue; } } else { $httpMethodsAllowed = array_merge($httpMethodsAllowed, $route->getHttpMethods()); } } if (!$dispatched) { if ($httpMethodsAllowed) { $this->response()->header('Allow', implode(' ', $httpMethodsAllowed)); $this->halt(405); } else { $this->notFound(); } } $this->response()->write(ob_get_clean()); $this->applyHook('slim.after.router'); $this->view->getData('flash')->save(); session_write_close(); $this->response->send(); $this->applyHook('slim.after'); } catch (Slim_Exception_RequestSlash $e) { $this->redirect($this->request->getRootUri() . $this->request->getResourceUri() . '/', 301); } catch (Exception $e) { if ($e instanceof Slim_Exception_Stop) { throw $e; } $this->getLog()->error($e); if ($this->config('debug') === true) { $this->halt(500, self::generateErrorMarkup($e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString())); } else { $this->error($e); } } } catch (Slim_Exception_Stop $e) { //Exit application context } }
public function render($template) { $this->setData('childView', $template); $template = $this->masterTemplate; return parent::render($template); }
/** * Render a template * * Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR * callable to render a template whose output is appended to the * current HTTP response body. How the template is rendered is * delegated to the current View. * * @param string $template The name of the template passed into the View::render method * @param array $data Associative array of data made available to the View * @param int $status The HTTP response status code to use (Optional) * @return void */ public function render($template, $data = array(), $status = null) { if (!is_null($status)) { $this->response->status($status); } $this->view->appendData($data); $this->view->display($template); }
<?php $partial = new Slim_View(); $partial->setTemplatesDirectory('partials'); function renderPartial($template, $data) { global $partial; $partial->setData($data); return $partial->render($template); }