当前位置: 首页>>代码示例>>PHP>>正文


PHP CakeResponse::statusCode方法代码示例

本文整理汇总了PHP中CakeResponse::statusCode方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeResponse::statusCode方法的具体用法?PHP CakeResponse::statusCode怎么用?PHP CakeResponse::statusCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CakeResponse的用法示例。


在下文中一共展示了CakeResponse::statusCode方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $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 += array('named' => $params['named'], 'pass' => $params['pass'], 'url' => array());
         $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(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
     $this->_stop();
 }
开发者ID:MrGrigorev,项目名称:reserva-de-salas,代码行数:33,代码来源:RedirectRoute.php

示例2: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if (!$params) {
         return false;
     }
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     $redirect = $this->defaults;
     if (count($this->defaults) == 1 && !isset($this->defaults['controller'])) {
         $redirect = $this->defaults[0];
     }
     if (isset($this->options['persist']) && is_array($redirect)) {
         $argOptions['context'] = array('action' => $redirect['action'], 'controller' => $redirect['controller']);
         $args = Router::getArgs($params['_args_'], $argOptions);
         $redirect += $args['pass'];
         $redirect += $args['named'];
     }
     $status = 301;
     if (isset($this->options['status']) && ($this->options['status'] >= 300 && $this->options['status'] < 400)) {
         $status = $this->options['status'];
     }
     $this->response->header(array('Location' => Router::url($redirect, true)));
     $this->response->statusCode($status);
     $this->response->send();
 }
开发者ID:no2key,项目名称:Web-Framework-Benchmark,代码行数:34,代码来源:redirect_route.php

示例3: parse

 /**
  * Parses a string url into an array. Parsed urls will result in an automatic
  * redirection
  *
  * @param string $url The url to parse
  * @return boolean False on failure
  */
 public function parse($url)
 {
     $params = parent::parse($url);
     if ($params === false) {
         return false;
     }
     $Domains = new Domains();
     $subdomain = $Domains->getSubdomain();
     $masterDomain = Configure::read('Domain.Master');
     $defaultRoute = Configure::read('Domain.DefaultRoute');
     $Tenant = new Tenant();
     if (!$Tenant->domainExists($subdomain) && $params != $defaultRoute) {
         if (!$this->response) {
             $this->response = new CakeResponse();
         }
         debug($this->response);
         die;
         $status = 307;
         $redirect = $defaultRoute;
         $this->response->header(array('Location' => Router::url($redirect, true)));
         $this->response->statusCode($status);
         $this->response->send();
         $this->_stop();
     }
     return $subdomain;
 }
开发者ID:bmilesp,项目名称:multi-tenancy,代码行数:33,代码来源:DomainRoute.php

示例4: testStatusCode

/**
* Tests the statusCode method
*
* @expectedException CakeException
*/
	public function testStatusCode() {
		$response = new CakeResponse();
		$this->assertEquals($response->statusCode(), 200);
		$response->statusCode(404);
		$this->assertEquals($response->statusCode(), 404);
		$this->assertEquals($response->statusCode(500), 500);

		//Throws exception
		$response->statusCode(1001);
	}
开发者ID:sherix88,项目名称:sigedu,代码行数:15,代码来源:CakeResponseTest.php

示例5: authenticate

 /**
  * Authenticate user
  *
  * @param CakeRequest $request The request object
  * @param CakeResponse $response response object.
  * @return mixed.  False on login failure.  An array of User data on success.
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $user = $this->getUser($request);
     if (!$user) {
         $response->statusCode(401);
         $response->send();
     }
     return $user;
 }
开发者ID:hardiksondagar,项目名称:cake-jwt-seed,代码行数:16,代码来源:JwtTokenAuthenticate.php

示例6: authenticate

 /**
  * Authenticate a user using basic HTTP auth.  Will use the configured User model and attempt a
  * login using basic HTTP auth.
  *
  * @param CakeRequest $request The request to authenticate with.
  * @param CakeResponse $response The response to add headers to.
  * @return mixed Either false on failure, or an array of user data on success.
  */
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $result = $this->getUser($request);
     if (empty($result)) {
         $response->header($this->loginHeaders());
         $response->statusCode(401);
         $response->send();
         return false;
     }
     return $result;
 }
开发者ID:MrGrigorev,项目名称:reserva-de-salas,代码行数:19,代码来源:BasicAuthenticate.php

示例7: asset

 /**
  * Checks if a requested asset exists and sends it to the browser
  *
  * @param $url string $url Requested URL
  * @return boolean True on success if the asset file was found and sent
  */
 public function asset($url)
 {
     if (strpos($url, '..') !== false || strpos($url, '.') === false) {
         return false;
     }
     $filters = Configure::read('Asset.filter');
     $isCss = strpos($url, 'ccss/') === 0 || preg_match('#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i', $url);
     $isJs = strpos($url, 'cjs/') === 0 || preg_match('#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i', $url);
     if (!$this->response) {
         $this->response = new CakeResponse();
     }
     if ($isCss && empty($filters['css']) || $isJs && empty($filters['js'])) {
         $this->response->statusCode(404);
         $this->response->send();
         return true;
     } elseif ($isCss) {
         include WWW_ROOT . DS . $filters['css'];
         return true;
     } elseif ($isJs) {
         include WWW_ROOT . DS . $filters['js'];
         return true;
     }
     $controller = null;
     $pathSegments = explode('.', $url);
     $ext = array_pop($pathSegments);
     $parts = explode('/', $url);
     $assetFile = null;
     if ($parts[0] === 'theme') {
         $themeName = $parts[1];
         unset($parts[0], $parts[1]);
         $fileFragment = implode(DS, $parts);
         $path = App::themePath($themeName) . 'webroot' . DS;
         if (file_exists($path . $fileFragment)) {
             $assetFile = $path . $fileFragment;
         }
     } else {
         $plugin = $parts[0];
         unset($parts[0]);
         $fileFragment = implode(DS, $parts);
         $pluginWebroot = App::pluginPath($plugin) . 'webroot' . DS;
         if (file_exists($pluginWebroot . $fileFragment)) {
             $assetFile = $pluginWebroot . $fileFragment;
         }
     }
     if ($assetFile !== null) {
         $this->_deliverAsset($assetFile, $ext);
         return true;
     }
     return false;
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:56,代码来源:dispatcher.php

示例8: beforeRender

 /**
  * test beforeRender() method
  *
  * @test
  */
 public function beforeRender()
 {
     $this->generateComponent(['mocks' => ['Api' => ['isApiRequest', 'failure', 'setResponse', '_getDbLog', 'getResponse']], 'componentOptions' => ['logDb' => true]]);
     $this->Api->expects($this->once())->method('failure');
     $this->Api->expects($this->once())->method('isApiRequest')->will($this->returnValue(true));
     $this->Api->expects($this->once())->method('_getDbLog')->will($this->returnValue('testDbLog'));
     $this->Api->expects($this->once())->method('setResponse')->with('dbLog', 'testDbLog');
     $this->Api->expects($this->once())->method('getResponse')->will($this->returnValue(['code' => 401]));
     $this->Api->beforeRender($this->controller);
     $this->assertSame(401, $this->response->statusCode());
     $this->assertArrayHasKey('response', $this->controller->viewVars);
     $this->assertSame(['code' => 401], $this->controller->viewVars['response']);
     $this->assertArrayHasKey('_serialize', $this->controller->viewVars);
     $this->assertSame('response', $this->controller->viewVars['_serialize']);
     $this->assertSame('Json', $this->controller->viewClass);
 }
开发者ID:hiromi2424,项目名称:api,代码行数:21,代码来源:ApiComponentTest.php

示例9: beforeRedirect

/**
 * Handles (fakes) redirects for Ajax requests using requestAction()
 *
 * @param Controller $controller A reference to the controller
 * @param string|array $url A string or array containing the redirect location
 * @param mixed $status HTTP Status for redirect
 * @param boolean $exit
 * @return void
 */
	public function beforeRedirect($controller, $url, $status = null, $exit = true) {
		if (!$this->request->is('ajax')) {
			return;
		}
		foreach ($_POST as $key => $val) {
			unset($_POST[$key]);
		}
		if (is_array($url)) {
			$url = Router::url($url + array('base' => false));
		}
		if (!empty($status)) {
			$statusCode = $this->response->httpCodes($status);
			$code = key($statusCode);
			$this->response->statusCode($code);
		}
		$this->response->body($this->requestAction($url, array('return', 'bare' => false)));
		$this->response->send();
		$this->_stop();
	}
开发者ID:sherix88,项目名称:sigedu,代码行数:28,代码来源:RequestHandlerComponent.php

示例10: beforeRedirect

 /**
  * Handles (fakes) redirects for Ajax requests using requestAction()
  * Modifies the $_POST and $_SERVER['REQUEST_METHOD'] to simulate a new GET request.
  *
  * @param Controller   $controller A reference to the controller
  * @param string|array $url        A string or array containing the redirect location
  * @param int|array    $status     HTTP Status for redirect
  * @param bool         $exit       Whether to exit script, defaults to `true`.
  *
  * @return void
  */
 public function beforeRedirect(Controller $controller, $url, $status = NULL, $exit = TRUE)
 {
     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));
     }
     if (!empty($status)) {
         $statusCode = $this->response->httpCodes($status);
         $code = key($statusCode);
         $this->response->statusCode($code);
     }
     $this->response->body($this->requestAction($url, array('return', 'bare' => FALSE)));
     $this->response->send();
     $this->_stop();
 }
开发者ID:mrbadao,项目名称:api-official,代码行数:35,代码来源:RequestHandlerComponent.php

示例11: redirect

 /**
  * Redirects to given $url, after turning off $this->autoRender.
  * Script execution is halted after the redirect.
  *
  * @param string|array $url A string or array-based URL pointing to another location within the app,
  *     or an absolute URL
  * @param int|array|null $status HTTP status code (eg: 301). Defaults to 302 when null is passed.
  * @param bool $exit If true, exit() will be called after the redirect
  * @return void
  * @triggers Controller.beforeRedirect $this, array($url, $status, $exit)
  * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::redirect
  */
 public function redirect($url, $status = null, $exit = true)
 {
     $this->autoRender = false;
     if (is_array($status)) {
         extract($status, EXTR_OVERWRITE);
     }
     $event = new CakeEvent('Controller.beforeRedirect', $this, array($url, $status, $exit));
     list($event->break, $event->breakOn, $event->collectReturn) = array(true, false, true);
     $this->getEventManager()->dispatch($event);
     if ($event->isStopped()) {
         return;
     }
     $response = $event->result;
     extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);
     if ($url !== null) {
         $this->response->header('Location', Router::url($url, true));
     }
     if (is_string($status)) {
         $codes = array_flip($this->response->httpCodes());
         if (isset($codes[$status])) {
             $status = $codes[$status];
         }
     }
     if ($status === null) {
         $status = 302;
     }
     $this->response->statusCode($status);
     if ($exit) {
         $this->response->send();
         $this->_stop();
     }
 }
开发者ID:amysupeta,项目名称:Exame1,代码行数:44,代码来源:Controller.php

示例12: redirect

 /**
  * Redirects to given $url, after turning off $this->autoRender.
  * Script execution is halted after the redirect.
  *
  * @param mixed $url A string or array-based URL pointing to another location within the app,
  *     or an absolute URL
  * @param integer $status Optional HTTP status code (eg: 404)
  * @param boolean $exit If true, exit() will be called after the redirect
  * @return mixed void if $exit = false. Terminates script if $exit = true
  * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::redirect
  */
 public function redirect($url, $status = null, $exit = true)
 {
     $this->autoRender = false;
     if (is_array($status)) {
         extract($status, EXTR_OVERWRITE);
     }
     $event = new CakeEvent('Controller.beforeRedirect', $this, array($url, $status, $exit));
     //TODO: Remove the following line when the events are fully migrated to the CakeEventManager
     list($event->break, $event->breakOn, $event->collectReturn) = array(true, false, true);
     $this->getEventManager()->dispatch($event);
     if ($event->isStopped()) {
         return;
     }
     $response = $event->result;
     extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);
     if (function_exists('session_write_close')) {
         session_write_close();
     }
     if (!empty($status) && is_string($status)) {
         $codes = array_flip($this->response->httpCodes());
         if (isset($codes[$status])) {
             $status = $codes[$status];
         }
     }
     if ($url !== null) {
         $this->response->header('Location', Router::url($url, true));
     }
     if (!empty($status) && ($status >= 300 && $status < 400)) {
         $this->response->statusCode($status);
     }
     if ($exit) {
         $this->response->send();
         $this->_stop();
     }
 }
开发者ID:MrGrigorev,项目名称:reserva-de-salas,代码行数:46,代码来源:Controller.php

示例13: redirect

/**
 * Redirects to given $url, after turning off $this->autoRender.
 * Script execution is halted after the redirect.
 *
 * @param mixed $url A string or array-based URL pointing to another location within the app,
 *     or an absolute URL
 * @param integer $status Optional HTTP status code (eg: 404)
 * @param boolean $exit If true, exit() will be called after the redirect
 * @return mixed void if $exit = false. Terminates script if $exit = true
 * @link http://book.cakephp.org/2.0/en/controllers.html#Controller::redirect
 */
	public function redirect($url, $status = null, $exit = true) {
		$this->autoRender = false;

		if (is_array($status)) {
			extract($status, EXTR_OVERWRITE);
		}
		$response = $this->Components->trigger(
			'beforeRedirect',
			array(&$this, $url, $status, $exit),
			array('break' => true, 'breakOn' => false, 'collectReturn' => true)
		);

		if ($response === false) {
			return;
		}
		extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);

		$response = $this->beforeRedirect($url, $status, $exit);
		if ($response === false) {
			return;
		}
		extract($this->_parseBeforeRedirect($response, $url, $status, $exit), EXTR_OVERWRITE);

		if (function_exists('session_write_close')) {
			session_write_close();
		}

		if (!empty($status) && is_string($status)) {
			$codes = array_flip($this->response->httpCodes());
			if (isset($codes[$status])) {
				$status = $codes[$status];
			}
		}

		if ($url !== null) {
			$this->response->header('Location', Router::url($url, true));
		}

		if (!empty($status) && ($status >= 300 && $status < 400)) {
			$this->response->statusCode($status);
		}

		if ($exit) {
			$this->response->send();
			$this->_stop();
		}
	}
开发者ID:sherix88,项目名称:sigedu,代码行数:58,代码来源:Controller.php

示例14: render

 /**
  * Display or download the given file
  *
  * @param string $view Not used
  * @param string $layout Not used
  * @return mixed
  * @throws NotFoundException
  */
 public function render($view = null, $layout = null)
 {
     $name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null;
     extract($this->viewVars, EXTR_OVERWRITE);
     if (is_dir($path)) {
         $path = $path . $id;
     } else {
         $path = APP . $path . $id;
     }
     if (!is_file($path)) {
         if (Configure::read('debug')) {
             throw new NotFoundException(sprintf('The requested file %s was not found', $path));
         }
         throw new NotFoundException('The requested file was not found');
     }
     if (is_array($mimeType)) {
         $this->response->type($mimeType);
     }
     if (isset($extension) && $this->_isActive()) {
         $extension = strtolower($extension);
         $chunkSize = 8192;
         $buffer = '';
         $fileSize = @filesize($path);
         $handle = fopen($path, 'rb');
         if ($handle === false) {
             return false;
         }
         if (!empty($modified) && !is_numeric($modified)) {
             $modified = strtotime($modified, time());
         } else {
             $modified = time();
         }
         if ($this->response->type($extension) === false) {
             $download = true;
         }
         if ($cache) {
             $this->response->cache($modified, $cache);
         } else {
             $this->response->header(array('Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT', 'Expires' => '0', 'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'no-cache'));
         }
         if ($download) {
             $agent = env('HTTP_USER_AGENT');
             if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
                 $contentType = 'application/octetstream';
             } else {
                 if (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
                     $contentType = 'application/force-download';
                 }
             }
             if (!empty($contentType)) {
                 $this->response->type($contentType);
             }
             if (is_null($name)) {
                 $name = $id;
             }
             $this->response->download($name);
             $this->response->header(array('Accept-Ranges' => 'bytes'));
             $httpRange = env('HTTP_RANGE');
             if (isset($httpRange)) {
                 list($toss, $range) = explode('=', $httpRange);
                 $size = $fileSize - 1;
                 $length = $fileSize - $range;
                 $this->response->header(array('Content-Length' => $length, 'Content-Range' => 'bytes ' . $range . $size . '/' . $fileSize));
                 $this->response->statusCode(206);
                 fseek($handle, $range);
             } else {
                 $this->response->header('Content-Length', $fileSize);
             }
         } else {
             $this->response->header(array('Content-Length' => $fileSize));
         }
         $this->_clearBuffer();
         if ($compress) {
             $this->_compressionEnabled = $this->response->compress();
         }
         $this->response->send();
         return $this->_sendFile($handle);
     }
     return false;
 }
开发者ID:Chromedian,项目名称:inventory,代码行数:88,代码来源:MediaView.php


注:本文中的CakeResponse::statusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。