本文整理汇总了PHP中Phalcon\Http\Response类的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: returnResult
public function returnResult($result, $errorMessage = null)
{
$response = new Response();
$result = ['result' => $result, 'status' => $errorMessage === null ? self::SUCCESS_RESPONSE : self::FAILED_RESPONSE, 'error_message' => (string) $errorMessage];
$response->setJsonContent($result);
return $response;
}
示例3: setUp
/**
*
*/
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$dispatcher = new Dispatcher();
$dispatcher->setDI($di);
$this->dispatcher = $dispatcher;
$cache = new BackendCache(new FrontendCache());
$di->set('viewCache', $cache);
$config = new Config(array('cache' => array('enable' => true)));
$di->set('config', $config);
$eventsManager = new Manager();
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('dispatcher', $dispatcher, true);
$di->set('eventsManager', $eventsManager);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例4: rawAction
public function rawAction()
{
$plain_response = new Response();
$plain_response->setHeader("Content-Type", "text/plain");
$plain_response->setContent($this->paste->content);
return $plain_response;
}
示例5: setUp
public function setUp()
{
$di = new DI();
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/path?foo=aaa&bar=bbb';
$_GET = array('_url' => '/path', 'foo' => 'aaa', 'bar' => 'bbb');
$request = new Request();
$request->setDI($di);
$this->request = $request;
$response = new Response();
$response->setDI($di);
$this->response = $response;
$eventsManager = new Manager();
$cors = new Cors(array(array('domain' => 'bar.com')));
$di->set('request', $request, true);
$di->set('response', $response, true);
$di->set('eventsManager', $eventsManager);
$di->set('cors', $cors);
$this->di = $di;
$application = new Application();
$application->setDI($di);
$application->setEventsManager($eventsManager);
$this->application = $application;
}
示例6: _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);
}
示例7: uploadAction
public function uploadAction()
{
$this->mediaModel = new Media();
if ($this->request->hasFiles() == true) {
$uploads = $this->request->getUploadedFiles();
$this->view->disable();
$uploaded = true;
foreach ($uploads as $fileObj) {
if (!$this->mediaModel->initFile($fileObj)) {
$uploaded = false;
}
}
$response = new Response();
if (!$uploaded) {
$error = implode("\n", $this->mediaModel->getError());
$response->setStatusCode(406, $error);
} else {
$response->setStatusCode(200, "Success");
}
return $response;
} else {
$this->assets->addCss('/core/assets/css/dropzone.css', false);
$this->assets->addJs('/core/assets/js/dropzone.js', false);
$this->view->acceptExt = implode(",", $this->constants->mediaAcceptFilesExt());
}
}
示例8: jsonResponse
protected function jsonResponse($data)
{
$response = new Response();
$response->setContentType('application/json', 'UTF-8');
$response->setJsonContent($data);
return $response;
}
示例9: response
/**
* @return Response
*/
public function response()
{
if ($this->__response === null) {
$this->__response = new Response();
$this->__response->setStatusCode(200);
}
return $this->__response;
}
示例10: logoutAction
/**
* Logout user, destroying session and invalidating remember me cookie. Forwards to login form.
*/
public function logoutAction()
{
$response = new Response();
$response->setCookies($this->cookies->set('username', '', strtotime('-1 year')));
$response->setCookies($this->cookies->set('password', '', strtotime('-1 year')));
$this->session->destroy();
return $response->redirect('session/index');
}
示例11: redirect
/**
* Returns an Redirect to the given url.
*
* @param string $url
* @return \Phalcon\Http\Response
*/
protected function redirect($url, $extraParams = array())
{
$response = new Response();
$response->redirect($url);
$formReflectionManager = new FormReflectionManager($this->flash);
$formReflectionManager->add($extraParams + $this->request->get());
return $response;
}
示例12: renderAJAX
/**
* Renders the uncaught exception for AJAX consumption.
*
* @param Phalcon\Http\Response $response
* @param \Exception $exceptio
* @return void
*/
protected function renderAJAX(Response $response, Exception $exception)
{
if ($this->config->debug) {
$response->setJsonContent(['_exception' => $exception->getMessage() . ': ' . $exception->getTraceAsString()]);
} else {
$response->setJsonContent(['status' => false]);
}
}
示例13: 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();
}
示例14: indexAction
/**
* Default action.
*/
public function indexAction()
{
$this->view->disable();
$data = ['Hello', 'World'];
$content = json_encode($data);
$response = new Response();
$response->setContent($content);
return $response;
}
示例15: sendResult
/**
* 发送数据
* @param mixed $result
*/
private static function sendResult($result)
{
$response = new Response();
$response->setHeader('Content-Type', 'application/json; charset=UTF-8');
$response->setHeader('Access-Control-Allow-Origin', '*');
$response->setJsonContent($result);
$response->send();
exit;
}