首页  /   默认版块  /   正文
谷歌浏览器添加JSON-Handle插件

迷失的音乐     默认版块     183     2019/04/02

谷歌浏览器添加JSON-Handle插件

以下是在Yii框架里面写的代码

<?php

namespace app\controllers;

use Yii;
use yii\web\controller;
use yii\web\Response;

class IndexController extends controller
{
    public function actionIndex()
    {
        $request = Yii::$app->request;
        $id = intval($request->get('id'));
        $param = [':id' => $id];
        $result = Yii::$app->db->createCommand('select * from user where id=:id')->bindValues($param)->queryAll();
        Yii::$app->response->format = Response::FORMAT_JSON;
        if ($result) {
            return [
                'message' => '返回数据成功',
                'code' => 200,
                'content' => $result
            ];
        } else {
            return [
                'message' => '返回数据失败',
                'code' => -1,
                'content' => '数据为空'
            ];
        }
    }
}

文章来源:赤砂之蝎我爱罗

文章最后更新于:2019-04-02 01:19:28

评论列表(0)
暂时还没有人评论!
发表评论