當前位置: 首頁>>代碼示例>>PHP>>正文


PHP json函數代碼示例

本文整理匯總了PHP中json函數的典型用法代碼示例。如果您正苦於以下問題:PHP json函數的具體用法?PHP json怎麽用?PHP json使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了json函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: update

 /**
  * @return \Response
  */
 public function update()
 {
     $this->passwordForm->validate(Input::all());
     $this->user()->password = Input::get('new_password');
     $this->user()->save();
     return json(trans('app.password_changed'));
 }
開發者ID:adriancatalinsv,項目名稱:fiip,代碼行數:10,代碼來源:PasswordController.php

示例2: validateDemo

 /**
  * 驗證演示
  *
  * @return \Slim\Http\Response
  */
 public function validateDemo()
 {
     $rules = ['username' => 'required', 'password' => 'required|confirmed', 'sex' => 'integer|in:1,0'];
     validate($this->request->post(), $rules);
     //以下是驗證通過的情況下
     return json(['status' => 'validation passes.']);
 }
開發者ID:ziyanziyu,項目名稱:rester,代碼行數:12,代碼來源:HomeController.php

示例3: ajax_check_code

 public function ajax_check_code()
 {
     $invite_code = $this->_get('invite_code');
     $org_code = $this->_get('org_code');
     if (!$invite_code || !$org_code) {
         return;
     }
     $f['code'] = $invite_code;
     $f['org_code'] = $org_code;
     $invite_data = M("InviteCodes")->where($f)->find();
     // 如果存在,寫對了,對bind++
     if ($invite_data) {
         $data['id'] = $invite_data['id'];
         $data['is_bind'] = $invite_data['is_bind'] + 1;
         M("InviteCodes")->save($data);
         $partner = M('Partners')->where(array('org_code' => $org_code))->find();
         if (!$partner) {
             $p_data['org_code'] = $org_code;
             $partner_id = M("Partners")->add($p_data);
         } else {
             $partner_id = $partner['id'];
         }
         json('check_code_callback(' . $partner_id . ',"' . $invite_data['org_name'] . '")', 'eval');
     } else {
         json('check_code_callback(0,"")', 'eval');
     }
 }
開發者ID:Germey,項目名稱:yinxingapply,代碼行數:27,代碼來源:ValidationAction.class.php

示例4: render

 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if (app()->environment('production')) {
         $title = 'Error';
         $description = 'Unknown error occurred :(';
         $statusCode = 400;
         if ($e instanceof ModelNotFoundException or $e instanceof NotFoundHttpException) {
             $title = trans('errors.not_found');
             $description = trans('errors.not_found_description');
             $statusCode = 404;
         }
         return response(view('errors.notice', ['title' => $title, 'description' => $description]), $e->getCode() ?: $statusCode);
     }
     if (is_api_request()) {
         $statusCode = method_exists($e, 'getStatusCode') ? $e->getStatusCode() : $e->getCode();
         if ($e instanceof TokenExpiredException) {
             $message = 'token_expired';
         } elseif ($e instanceof TokenInvalidException) {
             $message = 'token_invalid';
         } elseif ($e instanceof JWTException) {
             $message = $e->getMessage() ?: 'could_not_create_token';
         } elseif ($e instanceof NotFoundHttpException or $e instanceof ModelNotFoundException) {
             $statusCode = 404;
             $message = $e->getMessage() ?: 'not_found';
         } elseif ($e instanceof MethodNotAllowedHttpException) {
             $message = $e->getMessage() ?: 'not_allowed';
         } elseif ($e instanceof HttpResponseException) {
             return $e->getResponse();
         } elseif ($e instanceof Exception) {
             $message = $e->getMessage() ?: 'Whoops~ Tell me what you did :(';
         }
         return json()->setStatusCode($statusCode ?: 400)->error($message);
     }
     return parent::render($request, $e);
 }
開發者ID:corean,項目名稱:l5essential,代碼行數:42,代碼來源:Handler.php

示例5: get

 public function get()
 {
     $user = Auth::get();
     if ($user) {
         return json($user->newNotifications(), true);
     }
 }
開發者ID:fant0m,項目名稱:VAII,代碼行數:7,代碼來源:NotificationController.php

示例6: forbiddenResponse

 /**
  * {@inheritDoc}
  */
 public function forbiddenResponse()
 {
     if (is_api_request()) {
         return json()->forbiddenError();
     }
     return response('Forbidden', 403);
 }
開發者ID:linuxssm,項目名稱:l5essential,代碼行數:10,代碼來源:Request.php

示例7: delete

 public function delete()
 {
     $id = I('get.id');
     D('Message')->where('id=%d', $id)->delete();
     session('success', '刪除留言成功');
     json(NULL, 'refresh');
 }
開發者ID:Germey,項目名稱:SimpleCMS,代碼行數:7,代碼來源:MessageController.class.php

示例8: error

 /**
  * Create JSON error response.
  *
  * @param $message
  * @param int|null $code
  * @param array $data
  * @return bool|int
  */
 function error($message = null, $code = 501, $data = [])
 {
     if (is_int($code)) {
         http_response_code($code);
     }
     return json(array_merge(['error' => true, 'ok' => false], $message ? ['message' => $message] : [], $data));
 }
開發者ID:sphido,項目名稱:json,代碼行數:15,代碼來源:json.php

示例9: testResid

 public function testResid()
 {
     $redis = Cache::redis();
     $redis->set('up', json(['info' => 1111, 'name' => 'xiaohb']));
     //        $this->redis->flushAll();
     //        $this->redis->set('up',json(['info'=>1111,'name'=>'xiaohb']));
     return $redis->get('up');
 }
開發者ID:v3u3i87,項目名稱:upadd,代碼行數:8,代碼來源:HomeAction.php

示例10: deleteShortcut

 public function deleteShortcut(Request $request)
 {
     if (Shortcuts::where('user_id', $request->input('_user')['id'])->where('name', $request->input('name'))->delete()) {
         return json(['status' => 'ok']);
     } else {
         return json(error(2002));
     }
 }
開發者ID:koyeo,項目名稱:bichon,代碼行數:8,代碼來源:Config.php

示例11: request

 /**
  * 獲取請求記錄
  * @param 內容 $cont
  * @param 文件名稱以及格式 $file
  */
 public static function request($cont, $fileName = 'request.logs')
 {
     $cont['url'] = self::getHttpUrl();
     $cont['time'] = date('Y-m-d H:i:s');
     $content = json($cont) . ",\r";
     $file = self::isBak($fileName);
     file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
 }
開發者ID:v3u3i87,項目名稱:upadd,代碼行數:13,代碼來源:Log.php

示例12: ajax_change_type

 public function ajax_change_type()
 {
     $to = intval($this->_get('to'));
     $u['id'] = $this->login_user['id'];
     $u['apply_type_id'] = $to;
     M("UserInfo")->save($u);
     json(NULL, 'refresh');
 }
開發者ID:Germey,項目名稱:yinxingapply,代碼行數:8,代碼來源:UserinfoAction.class.php

示例13: delete

 public function delete($id)
 {
     $id = intval($id);
     // 關聯文章
     M('Tag')->where(array('id' => $id))->delete();
     session('success', '刪除標簽成功');
     json(NULL, 'refresh');
 }
開發者ID:Germey,項目名稱:SimpleCMS,代碼行數:8,代碼來源:TagController.class.php

示例14: extend

 function extend($path = '')
 {
     if (empty($path)) {
         json('1002', '模板路徑錯誤!');
     } else {
         $page = Page::init();
         $page->extend($path);
     }
 }
開發者ID:imjcw,項目名稱:framework,代碼行數:9,代碼來源:Page.php

示例15: webfiles_response

function webfiles_response($data)
{
    header('HTTP/1.1 200 OK');
    header('Content-Type: application/json');
    $data = json($data);
    header('Content-Length: ' . strlen($data));
    echo $data;
    exit;
}
開發者ID:vojtajina,項目名稱:sitellite,代碼行數:9,代碼來源:index.php


注:本文中的json函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。