本文整理汇总了PHP中Phalcon\Http\Response::setContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setContent方法的具体用法?PHP Response::setContent怎么用?PHP Response::setContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Http\Response
的用法示例。
在下文中一共展示了Response::setContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _renderJsonp
/**
* @param View $view
*/
protected function _renderJsonp(View $view)
{
$content = $this->getResponse()->setContentType('application/json')->setJsonContent($view->getParamsToView())->getContent();
$content = $this->request->get('callback') . '(' . $content . ')';
$this->response->setContent($content)->send();
$view->setRenderLevel(View::LEVEL_NO_RENDER);
}
示例2: renderBrowser
/**
* Renders the uncaught exception for browser consumption.
*
* @param Phalcon\Http\Response $response
* @param \Exception $exception
* @return void
*/
protected function renderBrowser(Response $response, Exception $exception)
{
if ($this->config->debug) {
$response->setContent($exception->getMessage() . ': ' . $exception->getTraceAsString());
} else {
$response->setContent('Sorry, an error has occured.');
}
}
示例3: send
/**
* 发送响应消息
*
* @param string $message 响应信息
* @param int $status 响应状态码
*/
public static function send($message = '', $status = 200)
{
if (self::$response === null) {
self::init();
}
self::$response->setStatusCode(intval($status));
self::$response->setContent(strval($message));
self::$response->send();
}
示例4: reset
public function reset()
{
static::$disableSession = false;
static::$disableCsrfCheck = false;
$this->cookies->reset();
$this->response->setContent('')->resetHeaders()->setStatusCode(200);
}
示例5: rawAction
public function rawAction()
{
$plain_response = new Response();
$plain_response->setHeader("Content-Type", "text/plain");
$plain_response->setContent($this->paste->content);
return $plain_response;
}
示例6: getCsrfTokenAction
/**
* Get CSRF token for Ajax request.
* @return a HTTP response object with JSON
*/
public function getCsrfTokenAction()
{
$result = array('csrfTokenKey' => $this->security->getTokenKey(), 'csrfToken' => $this->security->getToken());
$response = new Response();
$response->setContent(json_encode($result));
return $response;
}
示例7: accessToken
/**
* Exchange a request token for an access token.
* The exchange is only succesful iff the request token has been authorized.
*
* Never returns, calls exit() when token is exchanged or when error is returned.
*/
public function accessToken()
{
try {
$this->verifyRequest(self::TOKEN_TYPE_REQUEST);
$options = array();
$ttl = $this->request->get('xoauth_token_ttl');
if ($ttl) {
$options['token_ttl'] = $ttl;
}
$verifier = $this->request->get('oauth_verifier');
if ($verifier) {
$options['verifier'] = $verifier;
}
$store = $this->store;
$token = $store->exchangeConsumerRequestForAccessToken($this->request->getParam('oauth_token', true), $options);
/** @var /Foundation/Oauth/Secrets $token */
$content = array("oauth_token" => $token->token, "oauth_token_secret" => $token->token_secret);
if ($token->ttl) {
$content['xoauth_token_ttl'] = $token->ttl;
}
$this->response->setContent(http_build_query($content));
$this->response->setStatusCode(200, "");
$this->response->setContentType("application/x-www-form-urlencoded");
} catch (OauthException $e) {
$this->response->setStatusCode(401, "OAuth Verification Failed: " . $e->getMessage());
}
return $this->response;
}
示例8: indexAction
/**
* Default action.
*/
public function indexAction()
{
$this->view->disable();
$data = ['Hello', 'World'];
$content = json_encode($data);
$response = new Response();
$response->setContent($content);
return $response;
}
示例9: respond
/**
* Send response to client
*/
public function respond($data, $status = 200)
{
$response = new Response();
$response->setContentType('application/json');
$response->setStatusCode($status);
$data = $data instanceof SimpleResultSet ? $data->toArray() : $data;
$response->setContent(json_encode($data));
$response->send();
}
示例10: debugEnvAction
public function debugEnvAction()
{
//var_dump($_SERVER['REDIRECT_URL']);die();
$actual_route = $_SERVER['REDIRECT_URL'];
$response = new Response();
$response->setStatusCode(404, "Not Found");
$response->setContent("Sorry, the route: <b>" . $actual_route . " </b> doesn't exist");
$response->send();
return $response;
}
示例11: send
/**
* 向Client发送响应的资源
*/
public function send()
{
if (is_array($this->resource) || is_object($this->resource)) {
$this->response->setHeader('Content-Type', 'text/json');
$this->response->setContent(json_encode($this->resource, true));
} else {
$this->response->setContent($this->resource);
}
$this->response->send();
}
示例12: previewAction
/**
* @return Response
*/
public function previewAction()
{
$response = new Response();
if ($this->request->isPost()) {
if ($this->session->get('identity')) {
$content = $this->request->getPost('content');
$response->setContent($this->markdown->render($this->escaper->escapeHtml($content)));
}
}
return $response;
}
示例13: response
public function response($data = array(), $status = 200, $token = null)
{
$response = new Response();
$response->setStatusCode($status);
$response->setContent(!empty($this->_statuses[$status]) ? $this->_statuses[$status] : null);
$response->setHeader('Content-type', 'application/json');
$response->setHeader('api-version', '1.0');
$response->setHeader('singou-token', $token);
$response->setJsonContent($data);
return $response;
}
示例14: process
/**
* Выполняет все плагины по цепочке
*
* @param \Phalcon\Http\Request $request
* @return string
*/
public function process(Request $request)
{
$response = new Response();
$pluginResult = new PluginResult();
foreach ($this->_arPlugins as $plugin) {
$pluginResult = $plugin->process($request, $pluginResult);
if ($pluginResult->terminate) {
break;
}
}
if ($pluginResult->error) {
$response->setStatusCode($pluginResult->errorCode, $pluginResult->errorMessage);
$response->setContent($pluginResult->errorMessage);
return $response;
} else {
$response->setStatusCode(200, "OK");
}
$callback = $request->getQuery('callback');
$result = '';
if ($callback) {
$response->setHeader('Content-Type', 'application/javascript');
$result .= $callback . '(';
} else {
$response->setHeader('Content-Type', 'application/json');
}
$result .= json_encode(array('searchContext' => $pluginResult->searchContext, 'result' => $pluginResult->result));
if ($callback) {
$result .= ');';
}
if ($pluginResult->fileToSend) {
$response->setFileToSend($pluginResult->fileToSend, 'data.txt');
} else {
$response->setContent($result);
}
return $response;
}
示例15: indexAction
/**
* Generate the website robots.txt
*/
public function indexAction()
{
$response = new Response();
$expireDate = new \DateTime();
$expireDate->modify('+1 month');
$response->setExpires($expireDate);
$response->setHeader('Content-Type', "text/plain; charset=UTF-8");
$baseUrl = rtrim($this->config->site->url, '/');
$content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap
EOL;
$response->setContent($content);
return $response;
}