一、Php控制器跳转
return $this->redirect('/site/index/index');
二、回调自身控制器
self::actionXxxx();
三、获取当前用户信息
Yii::$app->user->identity->id;
四、获取当前MODULE
Yii::$app->controller->module->id
五、获取当前控制器
Yii::$app->controller->id
六、获取当前方法
Yii::$app->controller->action->id
七、获取当前页面get值
{% if app.request.get.game == '
XXXX' %}
八、活动对象更新数据
$a=Admin::findOne(['username'=>"0017"]);
$a->type=9;
$a->save();
九、Mongo AND OR 查询条件
['$and'=>[['oid'=>”880”,['$or'=>[['status'=>1],['status'=>2]]]]]
十、Mysql
['or', ['id' => 11], ['id' => 10]
或者->where()->orWhere()
十一、Ajax回调
Return functionsUtil::ajaxReturn(1,’
回调信息’);
public function ajaxReturn($status=0,$info='',$data=array()){
$json=[
'status' => $status,
'info' => $info,
'data' => $data,
];
return json_encode($json);
}
十二、Yii分页
$mess=Buyorder::find();
$count=$mess->count()
;
$pages=new Pagination(
['totalCount'=>$count,'pageSize'=>5]);.
$data['pages']= $pages;
$data['select']=$mess->offset($pages->offset)->orderBy(
['id'=>SORT_DESC])->limit($pages->limit)->asArray()->all();
{{ LinkPager(pages)|raw }}
十三、Mongo 排序
"time desc,status asc"
十四、取参数
Yii::$app->params['xxx']
十五、原生sql语句
$qsql = 'SELECT m.username,m.realname,w.money from member as m left join member_wealth as w on m.id=w.uid where w.money>=1000';
$qres = Yii::$app->db->createCommand($qsql)->queryAll();
十六、定时刷新页面
setTimeout(function(){ },1000)
十七、页面跳转
Window.location.href=””;
十八、页面退回
window.history.back(-1);
十九、字符拼接
JS + PHP .
二十、Db源码查询
Use yii\db
$db->createCommand(‘select * FROM database WHERE id =1’)->queryOne();
二十一、二维数组按某字段排序
$sort = array(
'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
'field' => 'createtime', //排序字段
);
$arrSort = array();
foreach($a AS $uniqid => $row){
foreach($row AS $key=>$value){
$arrSort[$key][$uniqid] = $value;
}
}
if($sort['direction']){
array_multisort($arrSort[$sort['field']], constant($sort['direction']), $a);
}
二十二、获取特定时间戳
//php
获取今日开始时间戳和结束时间戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
//php
获取昨日起始时间戳和结束时间戳
$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
//php
获取上周起始时间戳和结束时间戳
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
//php
获取本月起始时间戳和结束时间戳
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
二十三、mongo大于、小于、不等于
$where['
字段']= ['$gte'=>$beginToday,'$lte'=>$endToday];
$where['
字段']= ['$ne'=>$beginToday];
e<=>等于
二十四、表单提交
$.ajax({
url:'/operative/default/addspread',
type:'post',
processData : false, //
告诉jQuery不要去处理发送的数据
contentType : false, //
告诉jQuery不要去设置Content-Type请求头
data:new FormData($('#addspread')[0]),
dataType:'json',
success:function(data){
alert(1);
}
});
二十五、EXCEL导出
$data = Buyorder::find()->where($where)->andWhere(['>','paytime',$gte])->andWhere(['<','paytime',$lte])->andWhere(['<>','ispay',0])->asArray()->all();
$name = date('Y-m-d').('请用WPS打开');
Header("Content-type: application/octet-stream ");
Header("Accept-Ranges: bytes ");
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
Header("Content-Disposition:attachment;filename=$name.xlsx ");
echo '编号'.chr(9);
echo '订单号'.chr(9);
echo chr(13);
foreach ($data as $k=>$v){
echo $v['id'].chr(9);
echo $v['order_id'] .chr(9);
echo chr(13);
}
exit();
}
二十六、JS标签值获取
var time = $("input[name='time']").val();
二十七、别名
设置别名 Yii::setAlias('@app', dirname(__DIR__) . '/');
获取别名 Yii::getAlias('@app')