本文整理汇总了PHP中Cake\Network\Response::stop方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::stop方法的具体用法?PHP Response::stop怎么用?PHP Response::stop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Network\Response
的用法示例。
在下文中一共展示了Response::stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRedirect
/**
* Handles (fakes) redirects for Ajax requests using requestAction()
*
* @param Event $event The Controller.beforeRedirect event.
* @param string|array $url A string or array containing the redirect location
* @param \Cake\Network\Response $response The response object.
* @return void
*/
public function beforeRedirect(Event $event, $url, Response $response)
{
$request = $this->request;
if (!$request->is('ajax')) {
return;
}
if (empty($url)) {
return;
}
if (is_array($url)) {
$url = Router::url($url + ['_base' => false]);
}
$controller = $event->subject();
$response->body($controller->requestAction($url, ['return', 'bare' => false, 'environment' => ['REQUEST_METHOD' => 'GET']]));
$response->send();
$response->stop();
}
示例2: beforeRedirect
public function beforeRedirect(Event $event, $url, Response $response)
{
//
$logged_in = is_int($this->Controller->Auth->user('id'));
$login_action = false;
if (is_string($url)) {
if (stripos($url, 'login') !== false) {
$login_action = true;
}
} elseif (is_array($url)) {
if ($url['action'] == 'login') {
$login_action = true;
}
}
if ($this->request->is('service') && !$logged_in && $login_action) {
$this->data = [self::SUCCESS_KEY => false, self::ENABLE_KEY => true, self::CODE_KEY => 401, self::MESSAGE_KEY => __('You are not logged in!')];
$this->Controller->render();
$response->statusCode(201);
$response->send();
$response->stop();
if (session_id()) {
session_write_close();
}
}
}
示例3: beforeRedirect
/**
* Handles (fakes) redirects for Ajax requests using requestAction()
* Modifies the $_POST and $_SERVER['REQUEST_METHOD'] to simulate a new GET request.
*
* @param Event $event The Controller.beforeRedirect event.
* @param string|array $url A string or array containing the redirect location
* @param \Cake\Network\Response $response The response object.
* @return void
*/
public function beforeRedirect(Event $event, $url, $response)
{
if (!$this->request->is('ajax')) {
return;
}
if (empty($url)) {
return;
}
$_SERVER['REQUEST_METHOD'] = 'GET';
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
}
if (is_array($url)) {
$url = Router::url($url + array('base' => false));
}
$controller = $event->subject();
$response->body($controller->requestAction($url, array('return', 'bare' => false)));
$response->send();
$response->stop();
}
示例4: parse
/**
* Parses a string URL into an array. Parsed URLs will result in an automatic
* redirection
*
* @param string $url The URL to parse
* @return bool False on failure
*/
public function parse($url)
{
$params = parent::parse($url);
if (!$params) {
return false;
}
if (!$this->response) {
$this->response = new Response();
}
$redirect = $this->redirect;
if (count($this->redirect) === 1 && !isset($this->redirect['controller'])) {
$redirect = $this->redirect[0];
}
if (isset($this->options['persist']) && is_array($redirect)) {
$redirect += ['pass' => $params['pass'], 'url' => []];
if (is_array($this->options['persist'])) {
foreach ($this->options['persist'] as $elem) {
if (isset($params[$elem])) {
$redirect[$elem] = $params[$elem];
}
}
}
$redirect = Router::reverse($redirect);
}
$status = 301;
if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
$status = $this->options['status'];
}
$this->response->header(['Location' => Router::url($redirect, true)]);
$this->response->statusCode($status);
$this->response->send();
$this->response->stop();
}