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


PHP SS_HTTPResponse::setStatusCode方法代码示例

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


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

示例1: httpError

 public function httpError($code, $message = null)
 {
     $response = new SS_HTTPResponse();
     $response->setStatusCode($code);
     $response->addHeader('Content-Type', 'text/html');
     return $response;
 }
开发者ID:Thingee,项目名称:openstack-org,代码行数:7,代码来源:SurveyPage.php

示例2: upload

 /**
  * Action to handle upload of a single file
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  * @return SS_HTTPResponse
  */
 public function upload(SS_HTTPRequest $request)
 {
     if ($this->isDisabled() || $this->isReadonly() || !$this->canUpload()) {
         return $this->httpError(403);
     }
     // Protect against CSRF on destructive action
     $token = $this->getForm()->getSecurityToken();
     if (!$token->checkRequest($request)) {
         return $this->httpError(400);
     }
     // Get form details
     $name = $this->getName();
     $postVars = $request->postVar($name);
     // Save the temporary file into a File object
     $uploadedFiles = $this->extractUploadedFileData($postVars);
     $firstFile = reset($uploadedFiles);
     $file = $this->saveTemporaryFile($firstFile, $error);
     if (empty($file)) {
         $return = array('error' => $error);
     } else {
         $return = $this->encodeFileAttributes($file);
     }
     // Format response with json
     $response = new SS_HTTPResponse(Convert::raw2json(array($return)));
     $response->addHeader('Content-Type', 'text/plain');
     if (!empty($return['error'])) {
         $response->setStatusCode(200);
     }
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:37,代码来源:CustomUploadField.php

示例3: handleRequest

 public function handleRequest(SS_HTTPRequest $request, DataModel $model = NULL)
 {
     $body = null;
     $lang = i18n::get_locale();
     $path = Config::inst()->get('UniversalErrorPage', 'DefaultPath');
     if (!$path) {
         $path = $this->defaultErrorPagePath;
     }
     $forCode = Config::inst()->get('UniversalErrorPage', $this->ErrorCode);
     $localeForCode = preg_replace('/\\.([a-z]+)$/i', '-' . $lang . '.$1', $forCode);
     $errorPages = array($localeForCode, $forCode, $path . "error-{$this->ErrorCode}-{$lang}.html", $path . "error-{$this->ErrorCode}-{$lang}.php", $path . "error-{$lang}.html", $path . "error-{$lang}.php", $path . 'error.html', $path . 'error.php');
     $this->extend('updateHandleRequest', $errorPages);
     // now check if any of the pages exist
     foreach ($errorPages as $errorPage) {
         if (!$body && file_exists($errorPage)) {
             $ext = pathinfo($errorPage, PATHINFO_EXTENSION);
             if ($ext == 'php') {
                 ob_start();
                 include $errorPage;
                 $body = ob_get_clean();
             } else {
                 $body = file_get_contents($errorPage);
             }
             break;
         }
     }
     if ($body) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($this->ErrorCode);
         $response->setBody($body);
         return $response;
     }
     return parent::handleRequest($request, $model);
 }
开发者ID:Marketo,项目名称:SilverStripe-UniversalErrorPage,代码行数:34,代码来源:UniversalErrorPage.php

示例4: OnSitePhoneForm

 public function OnSitePhoneForm()
 {
     $request = Session::get('Current.PresentationSpeakerSummitAssistanceConfirmationRequest');
     if (is_null($request)) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode(404);
         return $response;
     }
     $form = new OnSitePhoneForm($this, 'OnSitePhoneForm', $request);
     $form->loadDataFrom($request);
     return $form;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:12,代码来源:SummitConfirmSpeakerPage.php

示例5: handleAssignBulkAction

 public function handleAssignBulkAction($gridField, $request)
 {
     $entity_id = $request->param('EntityID');
     $controller = $gridField->getForm()->Controller();
     $this->gridField = $gridField;
     $ids = $this->getRecordIDList();
     $this->processRecordIds($ids, $entity_id, $gridField, $request);
     $response = new SS_HTTPResponse(Convert::raw2json(array('done' => true, 'records' => $ids)));
     $response->addHeader('Content-Type', 'text/json');
     $response->setStatusCode(200);
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:12,代码来源:GridFieldBulkAction.php

示例6: member

 public function member()
 {
     $EmailAddress = "";
     $Member = "";
     // Make sure the access is POST, not GET
     if (!$this->request->isPOST()) {
         return $this->httpError(403, 'Access Denied.');
     }
     if (!defined('APPSEC')) {
         return $this->httpError(403, 'Access Denied.');
     }
     // Make sure the APPSEC shared secret matches
     if ($this->request->postVar('APPSEC') != APPSEC) {
         return $this->httpError(403, 'Access Denied.');
     }
     // Pull email address from POST variables
     $EmailAddress = $this->request->postVar('email');
     // Sanitize the input
     $EmailAddress = convert::raw2sql($EmailAddress);
     // If an email address was provided, try to find a member with it
     if ($EmailAddress) {
         $Member = Member::get()->filter('Email', $EmailAddress)->first();
     }
     $response = new SS_HTTPResponse();
     // If a member was found return status 200 and 'OK'
     if ($Member && $Member->isFoundationMember()) {
         $response->setStatusCode(200);
         $response->setBody('OK');
         $response->output();
     } elseif ($EmailAddress) {
         $response->setStatusCode(404);
         $response->setBody('No Member Found.');
         $response->output();
     } else {
         $response->setStatusCode(500);
         $response->setBody('An error has occurred retrieving a member.');
         $response->output();
     }
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:39,代码来源:MemberVerifyPage.php

示例7: write

 protected function write(array $record)
 {
     ini_set('display_errors', 0);
     // TODO: This coupling isn't ideal
     // See https://github.com/silverstripe/silverstripe-framework/issues/4484
     if (\Controller::has_curr()) {
         $response = \Controller::curr()->getResponse();
     } else {
         $response = new SS_HTTPResponse();
     }
     // If headers have been sent then these won't be used, and may throw errors that we wont' want to see.
     if (!headers_sent()) {
         $response->setStatusCode($this->statusCode);
         $response->addHeader("Content-Type", $this->contentType);
     } else {
         // To supress errors aboot errors
         $response->setStatusCode(200);
     }
     $response->setBody($record['formatted']);
     $response->output();
     return false === $this->bubble;
 }
开发者ID:hpeide,项目名称:silverstripe-framework,代码行数:22,代码来源:HTTPOutputHandler.php

示例8: handleDeleteAllSummitEntityEventsAction

 public function handleDeleteAllSummitEntityEventsAction($gridField, $request)
 {
     $summit_id = intval($request->param("ID"));
     $controller = $gridField->getForm()->Controller();
     $this->gridField = $gridField;
     $summit = Summit::get()->byID($summit_id);
     $status = 404;
     if (!is_null($summit)) {
         $status = 200;
         DB::query("DELETE FROM SummitEntityEvent WHERE SummitID = {$summit_id} ;");
     }
     $response = new SS_HTTPResponse();
     $response->setStatusCode($status);
     return $response;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:15,代码来源:GridFieldDeleteAllSummitEntityEventsAction.php

示例9: response_for

 /**
  * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an {@link ErrorPage} for that code is present.
  *
  * @param int $statusCode
  * @return SS_HTTPResponse
  */
 public static function response_for($statusCode)
 {
     // first attempt to dynamically generate the error page
     if ($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = {$statusCode}")) {
         return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
     }
     // then fall back on a cached version
     $cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
     if (file_exists($cachedPath)) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($statusCode);
         $response->setBody(file_get_contents($cachedPath));
         return $response;
     }
 }
开发者ID:prostart,项目名称:cobblestonepath,代码行数:21,代码来源:ErrorPage.php

示例10: postRequest

 /**
  * Filter executed AFTER a request
  *
  * @param SS_HTTPRequest $request Request container object
  * @param SS_HTTPResponse $response Response output object
  * @param DataModel $model Current DataModel
  * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
  */
 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     $code = $response->getStatusCode();
     $error_page_path = Director::baseFolder() . "/errors_pages/ui/{$code}/index.html";
     if (!$request->isAjax() && file_exists($error_page_path)) {
         //clean buffer
         ob_clean();
         $page_file = fopen($error_page_path, "r") or die("Unable to open file!");
         $body = fread($page_file, filesize($error_page_path));
         fclose($page_file);
         // set content type
         $response->addHeader('Content-Type', 'text/html');
         $response->setBody($body);
         $response->setStatusCode(200);
         return true;
     }
     return true;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:26,代码来源:HttpErrorRequestFilter.php

示例11: processform

 public function processform(SS_HTTPRequest $r)
 {
     $entry = BlogEntry::create();
     if ($this->request->postVar('Title') != null) {
         $entry->Title = $this->request->postVar('Title');
         $entry->Content = $this->request->postVar('Content');
         $entry->Tags = $this->request->postVar('Tags');
         $entry->Date = $this->request->postVar('Date');
         $entry->ParentID = $this->request->postVar('ParentID');
         $entry->write();
         $entry->publish('Stage', 'Live');
         $response = new SS_HTTPResponse(_t('Dashboard.Success', 'Successfully Published'), '200');
         $response->setStatusCode(200, _t('Dashboard.Posted', 'Blog Post Published'));
         return $response;
     } else {
         user_error('Blog Title and Content must be present', E_USER_ERROR);
     }
 }
开发者ID:helpfulrobot,项目名称:unclecheese-dashboard,代码行数:18,代码来源:DashboardBlogEntryPanel.php

示例12: response_for

 /**
  * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an
  * {@link ErrorPage} for that code is present. First tries to serve it 
  * through the standard SilverStripe request method. Falls back to a static
  * file generated when the user hit's save and publish in the CMS
  *
  * @param int $statusCode
  *
  * @return SS_HTTPResponse
  */
 public static function response_for($statusCode)
 {
     // first attempt to dynamically generate the error page
     $errorPage = ErrorPage::get()->filter(array("ErrorCode" => $statusCode))->first();
     if ($errorPage) {
         Requirements::clear();
         Requirements::clear_combined_files();
         return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
     }
     // then fall back on a cached version
     $cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
     if (file_exists($cachedPath)) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($statusCode);
         $response->setBody(file_get_contents($cachedPath));
         return $response;
     }
 }
开发者ID:riddler7,项目名称:silverstripe-cms,代码行数:28,代码来源:ErrorPage.php

示例13: handleGetAttendeesAction

    public function handleGetAttendeesAction($gridField, $request)
    {
        if (!Permission::check('ADMIN')) {
            return new SS_HTTPResponse(null, 403);
        }
        $term = Convert::raw2sql($request->getVar('term'));
        $summit_id = intval($request->param("ID"));
        $result = array();
        $sql = <<<SQL
SELECT A.ID,  CONCAT(M.FirstName,' ',M.Surname) AS FullName, M.Email  FROM SummitAttendee A INNER JOIN
Member M on M.ID = A.MemberID
WHERE A.SummitID = {$summit_id}
HAVING FullName LIKE '%{$term}%' OR M.Email LIKE '%{$term}% LIMIT 10;';
SQL;
        foreach (DB::query($sql) as $row) {
            array_push($result, array('id' => $row['ID'], 'label' => $row['FullName'] . ' ( ' . $row['Email'] . ' )'));
        }
        $response = new SS_HTTPResponse(Convert::raw2json($result));
        $response->addHeader('Content-Type', 'text/json');
        $response->setStatusCode(200);
        return $response;
    }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:22,代码来源:GridFieldWipeDevicesDataAction.php

示例14: httpError

 /**
  *	Display an error page on invalid request.
  *
  *	@parameter <{ERROR_CODE}> integer
  *	@parameter <{ERROR_MESSAGE}> string
  */
 public function httpError($code, $message = null)
 {
     // Determine the error page for the given status code.
     $errorPages = ClassInfo::exists('SiteTree') ? ErrorPage::get()->filter('ErrorCode', $code) : null;
     // Allow extension customisation.
     $this->extend('updateErrorPages', $errorPages);
     // Retrieve the error page response.
     if ($errorPages && ($errorPage = $errorPages->first())) {
         Requirements::clear();
         Requirements::clear_combined_files();
         $response = ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
         throw new SS_HTTPResponse_Exception($response, $code);
     } else {
         if ($errorPages && file_exists($cachedPage = ErrorPage::get_filepath_for_errorcode($code, class_exists('Translatable') ? Translatable::get_current_locale() : null))) {
             $response = new SS_HTTPResponse();
             $response->setStatusCode($code);
             $response->setBody(file_get_contents($cachedPage));
             throw new SS_HTTPResponse_Exception($response, $code);
         } else {
             return parent::httpError($code, $message);
         }
     }
 }
开发者ID:nyeholt,项目名称:silverstripe-misdirection,代码行数:29,代码来源:MisdirectionAdmin.php

示例15: applyToResponse

 /**
  * Copied and adjusted from HTTP::add_cache_headers
  *
  * @param Object $originator
  * @param SS_HTTPRequest $request
  * @param SS_HTTPResponse $response
  * @param DataModel $model
  */
 public function applyToResponse($originator, SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     $cacheAge = $this->cacheAge;
     // Development sites have frequently changing templates; this can get stuffed up by the code
     // below.
     if (Director::isDev()) {
         $cacheAge = 0;
     }
     // Populate $responseHeaders with all the headers that we want to build
     $responseHeaders = array();
     if (function_exists('apache_request_headers')) {
         $requestHeaders = apache_request_headers();
         if (isset($requestHeaders['X-Requested-With']) && $requestHeaders['X-Requested-With'] == 'XMLHttpRequest') {
             $cacheAge = 0;
         }
         // bdc: now we must check for DUMB IE6:
         if (isset($requestHeaders['x-requested-with']) && $requestHeaders['x-requested-with'] == 'XMLHttpRequest') {
             $cacheAge = 0;
         }
     }
     if ($cacheAge > 0) {
         $responseHeaders["Cache-Control"] = "max-age=" . $cacheAge . ", must-revalidate, no-transform";
         $responseHeaders["Pragma"] = "";
         $responseHeaders['Vary'] = $this->vary;
     } else {
         if ($response) {
             // Grab header for checking. Unfortunately HTTPRequest until 3.1 uses a mistyped variant.
             $contentDisposition = $response->getHeader('Content-disposition');
             if (!$contentDisposition) {
                 $contentDisposition = $response->getHeader('Content-Disposition');
             }
         }
         if ($response && Director::is_https() && strstr($_SERVER["HTTP_USER_AGENT"], 'MSIE') == true && strstr($contentDisposition, 'attachment;') == true) {
             // IE6-IE8 have problems saving files when https and no-cache are used
             // (http://support.microsoft.com/kb/323308)
             // Note: this is also fixable by ticking "Do not save encrypted pages to disk" in advanced options.
             $responseHeaders["Cache-Control"] = "max-age=3, must-revalidate, no-transform";
             $responseHeaders["Pragma"] = "";
         } else {
             $responseHeaders["Cache-Control"] = "no-cache, max-age=0, must-revalidate, no-transform";
         }
     }
     if (self::$modification_date && $cacheAge > 0) {
         $responseHeaders["Last-Modified"] = self::gmt_date(self::$modification_date);
         // Chrome ignores Varies when redirecting back (http://code.google.com/p/chromium/issues/detail?id=79758)
         // which means that if you log out, you get redirected back to a page which Chrome then checks against
         // last-modified (which passes, getting a 304)
         // when it shouldn't be trying to use that page at all because it's the "logged in" version.
         // By also using and etag that includes both the modification date and all the varies
         // values which we also check against we can catch this and not return a 304
         $etagParts = array(self::$modification_date, serialize($_COOKIE));
         $etagParts[] = Director::is_https() ? 'https' : 'http';
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             $etagParts[] = $_SERVER['HTTP_USER_AGENT'];
         }
         if (isset($_SERVER['HTTP_ACCEPT'])) {
             $etagParts[] = $_SERVER['HTTP_ACCEPT'];
         }
         $etag = sha1(implode(':', $etagParts));
         $responseHeaders["ETag"] = $etag;
         // 304 response detection
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             $ifModifiedSince = strtotime(stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']));
             // As above, only 304 if the last request had all the same varies values
             // (or the etag isn't passed as part of the request - but with chrome it always is)
             $matchesEtag = !isset($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] == $etag;
             if ($ifModifiedSince >= self::$modification_date && $matchesEtag) {
                 if ($response) {
                     $response->setStatusCode(304);
                     $response->setBody('');
                 } else {
                     header('HTTP/1.0 304 Not Modified');
                     die;
                 }
             }
         }
         $expires = time() + $cacheAge;
         $responseHeaders["Expires"] = self::gmt_date($expires);
     }
     if (self::$etag) {
         $responseHeaders['ETag'] = self::$etag;
     }
     // Now that we've generated them, either output them or attach them to the SS_HTTPResponse as appropriate
     foreach ($responseHeaders as $k => $v) {
         $response->addHeader($k, $v);
     }
 }
开发者ID:mateusz,项目名称:controllerpolicy,代码行数:95,代码来源:BackwardsCompatibleCachingPolicy.php


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