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


PHP Response::jsend方法代码示例

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


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

示例1: boot

 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->package('vena/jsend4laravel', 'jsend4laravel');
     /**
      * Wrapper for sending a JSON response with automatic JSONP support
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsend', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
         $response = Response::json($data, $httpStatus, $headers);
         if (Input::has('callback')) {
             $response->setCallback(Input::get('callback'));
         }
         return $response;
     });
     /**
      * Return a JSend success response
      * 
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendSuccess', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
         return Response::jsend((object) array('status' => 'success', 'data' => $data), $httpStatus, $headers);
     });
     /**
      * Return a JSend fail response
      *
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendFail', function ($data, $httpStatus = 400, array $headers = array()) {
         $responseData = (object) array('status' => 'fail', 'data' => $data);
         return Response::jsend($responseData, $httpStatus, $headers);
     });
     /**
      * Return a JSend error response
      *
      * @param  string        $message  (required) Message describing the error.
      * @param  int           $code     (optional) An internal error code, if applicable
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendError', function ($message = NULL, $code = NULL, $data = NULL, $httpStatus = 400, array $headers = array()) {
         if (is_null($message)) {
             throw new \BadMethodCallException($this->app['translator']->get('jsend4laravel::messages.jsend_errors_must_have_messages'));
         }
         $responseData = (object) array('status' => 'error', 'message' => $message);
         if (!is_null($code)) {
             $responseData->code = $code;
         }
         if (!is_null($data)) {
             $responseData->data = $data;
         }
         return Response::jsend($responseData, $httpStatus, $headers);
     });
 }
开发者ID:vena,项目名称:jsend4laravel,代码行数:72,代码来源:JSend4LaravelServiceProvider.php


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