本文整理汇总了PHP中http::json方法的典型用法代码示例。如果您正苦于以下问题:PHP http::json方法的具体用法?PHP http::json怎么用?PHP http::json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http
的用法示例。
在下文中一共展示了http::json方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: act_message
static function act_message()
{
if (post('message_submit', 'isset')) {
//检查验证码
$check_code = post('code', 'post');
if ($check_code != session('message_code', true)) {
http::json(array('error' => 2, 'info' => 'check_code error'));
}
//接收、过滤数据
$data['user_name'] = post('name', 'title');
$data['tel'] = post('contact_tel', 'number');
$data['phone'] = post('contact_phone', 'account');
$data['email'] = post('email', 'account');
$data['message'] = post('message_content', 'info');
//验证数据
$data['tel'] = safe::reg($data['tel'], 'tel') ? $data['tel'] : null;
$data['phone'] = safe::reg($data['phone'], 'phone') ? $data['phone'] : null;
$data['email'] = safe::reg($data['email'], 'email') ? $data['email'] : null;
if ($data['message']) {
$add_result = db::add('message', $data);
//将数据写入留言表
if ($add_result) {
http::json(array('error' => 0, 'info' => 'add message succeed'));
}
}
}
//以json格式返回给浏览器
http::json(array('error' => 1, 'info' => 'add message failed'));
}
示例2: upload
function upload()
{
if (isset($_FILES['imgFile'])) {
try {
$save_name = $this->user_id . '_' . date("dHis");
$upload = new s_upload($_FILES['imgFile'], $save_name, 5, 'editor', date('ym') . '/');
$file_name = $upload->get('file_name');
http::json(array('error' => 0, 'url' => U_R_L . strstr($file_name, 'file/editor/')));
} catch (sException $e) {
$message = config('error.' . $e->error, 'upload');
http::json(array('error' => 1, 'message' => $message));
}
}
http::json(array('error' => 1, 'message' => 'system busy, please try again later'));
}
示例3: check_admin
private static function check_admin($account, $password)
{
//用配置管理员数据(可换数据库)
$admin_account = config('admin|account', 'message_admin');
$account_list = explode(',', $admin_account);
if (!$account || !in_array($account, $account_list)) {
http::json(array('error' => 3, 'info' => 'inexistent account'));
}
if ($password != config('password|' . $account, 'message_admin')) {
http::json(array('error' => 4, 'info' => 'password error'));
}
$admin_access = config('access|' . $account, 'message_admin');
session('admin', array('account' => $account, 'access' => $admin_access));
http::json(array('error' => 0, 'info' => 'login succeed', 'url' => dc_url . 'message/manage'));
}
示例4: email_reply
function email_reply()
{
//验证权限,跳转提示页面
if (!in_array(parent::reply_access, $this->admin_access)) {
http::skip('login/forbid');
}
$tip_info = array('error' => 1, 'info' => 'send email failed');
if (post('email', 'isset')) {
//接收数据
$email = post('email', 'post');
$title = post('title', 'title');
$content = post('content', 'info');
//发送邮件
mail::send($email, $title, $content);
$tip_info = array('error' => 0, 'info' => 'email sent');
}
http::json($tip_info);
}
示例5: check_tip
static function check_tip($value, $rule, $type, $tip)
{
if (self::check($value, $rule, $type)) {
return true;
}
if (is_array($tip)) {
http::json($tip);
}
http::script($tip, 'alert');
}
示例6: edit
static function edit()
{
$img_name = post('img_name', 'title');
list($width, $height) = getimagesize($img_name);
$p_width = post('p_w', 'int');
$p_height = post('p_h', 'int');
//先缩放
$res = imagecreatetruecolor($p_width, $p_height);
$img = img::open($img_name);
imagecopyresampled($res, $img, 0, 0, 0, 0, $p_width, $p_height, $width, $height);
img::clear($img);
//再裁切
$new_img = imagecreatetruecolor(post('n_w', 'int'), post('n_h', 'int'));
imagecopyresampled($new_img, $res, 0, 0, post('t_x', 'int'), post('t_y', 'int'), $p_width, $p_height, $p_width, $p_height);
$img_name = basename($img_name);
img::save($new_img, $img_name, dc_file_create);
http::json(array('error' => 0, 'info' => $img_name), true);
}
示例7: bootstrap
static function bootstrap($controller, $method)
{
try {
if ($controller && $method) {
define('CURRENT_ACTION', substr($controller . ':' . $method, 2));
if (property_exists($controller, 'static_class')) {
if (method_exists($controller, '__before')) {
call_user_func($controller . '::__before');
}
call_user_func(array($controller, $method), explode('/', URL_REQUEST));
if (method_exists($controller, '__after')) {
call_user_func($controller, '::__after');
}
} else {
$object = new $controller();
if (method_exists($controller, '__before')) {
$object->__before();
}
call_user_func_array(array($object, $method), array(explode('/', URL_REQUEST)));
if (method_exists($controller, '__after')) {
$object->__after();
}
}
} else {
throw new Exception('absent controller or method', 101);
}
} catch (Exception $e) {
logger::exception('exception', $e->getCode() . ' : ' . $e->getMessage());
if (preg_match('/^(similar|product)$/', ENVIRONMENT)) {
if (http::is_ajax()) {
http::json(array('error' => 4, 'message' => $e->getMessage(), 'data' => null));
} else {
http::abort($e->getMessage(), '', 10);
}
}
debug::exception($e);
}
}
示例8: verify_tip
static function verify_tip($value, $option, $tip)
{
if (self::verify($value, $option)) {
return true;
}
if (is_array($tip)) {
http::json($tip);
}
http::script($tip, 'alert');
}