本文整理汇总了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'));
}
示例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.']);
}
示例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');
}
}
示例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);
}
示例5: get
public function get()
{
$user = Auth::get();
if ($user) {
return json($user->newNotifications(), true);
}
}
示例6: forbiddenResponse
/**
* {@inheritDoc}
*/
public function forbiddenResponse()
{
if (is_api_request()) {
return json()->forbiddenError();
}
return response('Forbidden', 403);
}
示例7: delete
public function delete()
{
$id = I('get.id');
D('Message')->where('id=%d', $id)->delete();
session('success', '删除留言成功');
json(NULL, 'refresh');
}
示例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));
}
示例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');
}
示例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));
}
}
示例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);
}
示例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');
}
示例13: delete
public function delete($id)
{
$id = intval($id);
// 关联文章
M('Tag')->where(array('id' => $id))->delete();
session('success', '删除标签成功');
json(NULL, 'refresh');
}
示例14: extend
function extend($path = '')
{
if (empty($path)) {
json('1002', '模板路径错误!');
} else {
$page = Page::init();
$page->extend($path);
}
}
示例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;
}