ToJson.php 870 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/2/26/026
  6. * Time: 15:48
  7. */
  8. namespace frontend\base;
  9. use Yii;
  10. use yii\web\Response;
  11. class ToJson
  12. {
  13. public static function JsonData($data,$count = 0)
  14. {
  15. Yii::$app->response->format=Response::FORMAT_JSON;
  16. $list['rows'] = !empty($data) ? $data : [] ;
  17. $list['total'] = $count;
  18. return $list;
  19. }
  20. /*
  21. * code 返回状态码 100=失败 200=成功
  22. * msg 返回信息
  23. * data 返回数据 格式 array
  24. * */
  25. public static function JsonCode($code,$msg = '',$data = null)
  26. {
  27. Yii::$app->response->format=Response::FORMAT_JSON;
  28. $list['code'] = $code;
  29. $list['msg'] = $msg;
  30. $list['data'] = $data;
  31. return $list;
  32. }
  33. }