本文整理汇总了PHP中Response::render方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::render方法的具体用法?PHP Response::render怎么用?PHP Response::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* @param Request $req
* @param Response $res
* @param array $allowedMethods
*
* @return Response
*/
public function __invoke($req, $res, $allowedMethods)
{
if ($req->isHtml()) {
$res->render(new View('method_not_allowed', ['title' => 'Method Not Allowed', 'allowedMethods' => $allowedMethods]));
}
return $res->setCode(405);
}
示例2: testRenderException
public function testRenderException()
{
$request = $this->makeRequest();
$response = new Response($request);
$this->setExpectedException('UnderflowException', 'You must set controller before calling this method.');
$response->render('tpl');
}
示例3: __invoke
/**
* @param Request $req
* @param Response $res
*
* @return Response
*/
public function __invoke($req, $res)
{
if ($req->isHtml()) {
$res->render(new View('not_found', ['title' => 'Not Found']));
}
return $res->setCode(404);
}
示例4: __invoke
/**
* @param Request $req
* @param Response $res
* @param \Exception $e
*
* @return Response
*/
public function __invoke($req, $res, \Exception $e)
{
$this->app['logger']->error('An uncaught exception occurred while handling a request.', ['exception' => $e]);
if ($req->isHtml()) {
$res->render(new View('exception', ['title' => 'Internal Server Error', 'exception' => $e]));
}
return $res->setCode(500);
}
示例5: render
/**
* Returns the rendered html
* @return the rendered html
*/
public function render()
{
parent::render();
if ($this->renderAs === 'blank') {
$template = new \OCP\Template($this->appName, $this->templateName);
} else {
$template = new \OCP\Template($this->appName, $this->templateName, $this->renderAs);
}
foreach ($this->params as $key => $value) {
$template->assign($key, $value, false);
}
return $template->fetchPage();
}
示例6: render
/**
* Returns the rendered json
* @return the rendered json
*/
public function render()
{
parent::render();
ob_start();
if ($this->error) {
\OCP\JSON::error($this->data);
} else {
\OCP\JSON::success($this->data);
}
$result = ob_get_contents();
ob_end_clean();
return $result;
}
示例7: run
public function run()
{
try {
if (!$this->router->match($this->request->getMethod(), $this->request->getUrl())) {
throw new \Exception('No route match url', 404);
}
$controllerClass = '\\Controllers\\' . ucfirst($this->router->getController()) . 'Controller';
$action = $this->router->getAction() . 'Action';
$controller = new $controllerClass($this);
$response = call_user_func_array(array($controller, $action), $this->router->getParameters());
$response->setApp($this);
$response->render();
} catch (\Exception $e) {
$code = $e->getCode() === 404 ? 404 : 500;
$response = new Response($code . '.html', array('msg' => $e->getMessage()));
$response->setApp($this);
$response->render();
}
}
示例8: run
/**
* 1) Initialise the Request
* 2) Grab the AssetType based on the request and initialise it
* 3) Instantiate the Response class, set the headers, and then return the content
*
* Rap everything in a Try/Catch block for error handling
*
* @param Request $Request
* @param array $options
*
* @return string
*
* @catch NotFoundException
* @catch ErrorException
*/
public static function run(Request $Request, $options = array())
{
try {
/**
* Merge in default options
*/
$options = array_merge(self::$defaultOptions, $options);
/**
* Set the header controller. Can be overwritten by the dispatcher options
*/
if (isset($options['headerController']) && $options['headerController'] instanceof Asset\HeaderSetter) {
$headerController = $options['headerController'];
} else {
$headerController = new Asset\HeaderSetter();
}
/**
* Initialise the Request
*/
$Request->init();
/**
* Grab the correct AssetType
*/
$AssetType = Asset\Registry::getClass($Request);
/**
* Initialise the AssetType
*/
$AssetType->init();
/**
* Create a response
*/
$Response = new Response($AssetType);
$Response->setHeaderController($headerController);
/**
* Set the headers if told to do so
*/
if ($options['setHeaders']) {
/**
* Set the headers.
*/
$Response->setHeaders($options['maxAge']);
}
/**
* If the content hasn't been modified return null so only headers are sent
* otherwise return the content
*/
return $Response->notModified ? null : $Response->render();
} catch (Asset\NotFoundException $e) {
if (isset($headerController) && $headerController instanceof Asset\HeaderSetter) {
$headerController->statusCode('HTTP/1.0', 404, 'Not Found');
$headerController->headerField('Status', '404 Not Found');
}
return 'Not Found Error: ' . static::getErrors($e);
} catch (Asset\Type\CompilationException $e) {
if (isset($AssetType) && $AssetType instanceof Asset\Type) {
$AssetType->cleanUpAfterError();
}
return 'Compilation Error: ' . static::getErrors($e);
} catch (ErrorException $e) {
return 'Error: ' . static::getErrors($e);
}
}
示例9: get
public function get()
{
$response = new Response();
return $response->render('partials/table', array('this' => $this), $fetch = true);
}
示例10: getSummary
public function getSummary()
{
$response = new Response();
return $response->render('partials/debug.tpl', array('profiler' => $this), true);
}
示例11: render
public function render()
{
$vars = $this->getVars();
$response = new Response();
return $response->render('partials/form.tpl', $vars, $fetch = true);
}
示例12: run
public function run()
{
// Se usa un contexto global para el render
return Response::render('homepage');
}
示例13: render
/**
* Simply sets the headers and returns the file contents
* @return the file contents
*/
public function render()
{
parent::render();
return $this->content;
}
示例14: header
<?php
try {
require_once '../config/core.conf.php';
header('Content-type: text/html; charset=' . Lang::$encoding);
//$profiler = new Profiler();
$controller = new ActionController();
$controller->handle();
//$profiler->stop();
//echo $profiler->getSummary();
} catch (Exception $e) {
$response = new Response();
if ($e instanceof AutoloadException || $e instanceof ViewException) {
$response->render('500');
}
if ($e instanceof ActionControllerException) {
$response->render('404');
}
$class_exception = get_class($e);
$msg_exception = $class_exception . ' : ' . $e->getMessage();
Logger::log($msg_exception);
if (CORE_DEBUG) {
echo '<pre>' . $msg_exception . '</pre>';
}
}
示例15: redirect
/**
* Returns a RedirectResponse to the given URL.
*
* @param string $url The URL to redirect to
* @param integer $status The status code to use for the Response
*
* @return RedirectResponse
*/
public function redirect($url, $status = 302)
{
$this->redirectWithHtml($url);
$this->response->addHeader('location', $url);
return $this->response->render();
}