摘要:一、Php控制器跳转return$this->redirect('/site/index/index');二、回调自身控制器self::actionXxxx();三、获取当前用户信息Yii::$app->user->identity->id;四、获取当前MODULEYii::$app->controller->module->id五、获取当前控制器Yii::$app->controller->id
十三、Mongo 排序
"time desc,status asc"
十四、取参数
Yii::$app->params['xxx']
十五、原生sql语句
$qsql='SELECTm.username,m.realname,w.moneyfrommemberasmleft joinmember_wealthaswon m.id=w.uidwherew.money>=1000';
$qres=Yii::$app->db->createCommand($qsql)->queryAll();
十六、定时刷新页面
setTimeout(function(){ },1000)
十七、页面跳转
Window.location.href=””;
十八、页面退回
window.history.back(-1);
十九、字符拼接
JS + PHP .
二十、Db源码查询
Use yiidb
$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')