qqa4560354
- qqa4560354 回复了 zhoupenghui 的回答
根据ActiveDataProvider中可以知道:
/** * @var QueryInterface the query that is used to fetch data models and [[totalCount]] * if it is not explicitly set. */ public $query;
说明$query数据是model
那我要让一个数组,分页,怎么写,,这里是接口,没有视图,
- qqa4560354 回答了问题 yii 开发API接口
public static function format_data($code,$data){ $msg = Yii::$app->params['a'.$code]; return ['code'=>$code,'msg'=>$msg,'data'=>$data]; }
- qqa4560354 提出了问题dataProvider分页
- qqa4560354 2017-01-17 已签到连续签到2天,获得了10个金钱
- qqa4560354 2017-01-16 已签到连续签到1天,获得了5个金钱
- qqa4560354 2017-01-14 已签到连续签到4天,获得了20个金钱
- qqa4560354 2017-01-13 已签到连续签到3天,获得了15个金钱
- qqa4560354 2017-01-12 已签到连续签到2天,获得了10个金钱
- qqa4560354 赞了回答
建议批量插入好点,如:
//假如 $names = ['zhangsan', 'lisi']; $data = []; foreach ($names $k => $v) { $data[] = [$v]; } Yii::$app->db->createCommand()->batchInsert('test', ['name'], $data)->execute();
- qqa4560354 回复了 天境之韫 的回答
把code和message与你接口要返回的数据组成一个新数组,转json后返回就可以了
定义到公共位置,比如说helper类,然后,return Helper::format_data(SUCC,$dataProvider);这样,succ,跟error,把1楼的转json带入就ok