/**
* 添加入库
* @return [type] [description]
*/
function actionIndex(){
$request = \Yii::$app->request;
$db = \Yii::$app->db;
if($request->post())
{
//文件上传
// $file=$_FILES['u_file'];
$data = $request->post();
$upload=new UploadedFile(); //实例化上传类
$filename=$upload->getInstanceByName('u_file'); //获取文件原名称
// p($filename);
$img=$_FILES['u_file']; //获取上传文件参数
$upload->tempName=$img['tmp_name']; //设置上传的文件的临时名称
$img_path='../uploads/'.$filename; //设置上传文件的路径名称(这里的数据进行入库)
// p($img_path);
$arr=$upload->saveAs($img_path); //保存文件
// P($arr);
$data['u_file']=$img_path;
// p($data);
unset($data['_csrf']);
$res=$db->createCommand()->insert('login', $data)->execute();
if($res){
$this->redirect(array('/index/show/'));
}
}
else
{
return $this->render('index.html');
}
}
/**
* 查询展示
*/
function actionShow(){
$log= new login();
$re = $log->find();
// print_r($data);die;
$pages = new Pagination([
//'totalCount' => $countQuery->count(),
'totalCount' => $re->count(),
'pageSize' => 5 //每页显示条数
]);
$data = $re->offset($pages->offset)->limit($pages->limit)->all();//偏移量、每页条数
// $connection = \Yii::$app->db;
// $command = $connection->createCommand('SELECT * FROM login')->queryAll();
// print_r($command);die;
return $this->render('show.html',['data'=>$data,'pages'=>$pages]);
}