批改状态:合格
老师批语:
<?php
/**
* @Author: owlcity
* @Date: 2018-05-31 11:12:33
* @Last Modified by: owlcity
* @Last Modified time: 2018-05-31 18:05:47
*/
namespace app\index\controller;
use think\Controller;
use app\index\model\Test as TestModel;
use think\facade\Request;
class Test extends Controller{
public function demo1(){
$staffs = TestModel::all(function($query){
$query->field(['staff_id','name','sex','age','salary']);
// ->where('salary < 100');
});
// dump($staffs);
// 用all则不行
// all select find一样 都是查询方法需要查询条件
// 不指定查询条件也可以
$employ = TestModel::paginate(7);
// $config = [
// 'type'=> 'bootstrap',
// 'var_page'=> 'page'
// ];
// $num = 10;
// $simple = false;
// $employ = TestModel::paginate($num,$simple,$config);
$page = $employ->render();
$this->view->assign('staff',$employ);
$this->view->assign('page',$page);
return $this->view->fetch();
}
public function demo2(){
return $this->view->fetch();
}
public function demo3(){
$file = Request::file('file');
// dump($file);
if(is_null($file)){
$this->Error("文件文件空");
};
$rule = [
'size'=> 3072121,
'ext'=> 'jpeg,jpg,png,gif',
'type'=>'image/jpeg,image/jpg,image/png,image/gif'
];
// validate检测;
$info = $file->validate($rule)->move('uploads');
if($info){
echo $info->getSaveName();
}else{
$this->Error('上传失败');
}
// check检测
if($file->check($rule)) {
$fileInfo = $file->move('uploads');
// $fileInfo = $file->move('uploads','');//如果使用原文件名 第二个参数为空
$res = '<h3 style="color:green;">上传成功</h3>文件名是:'.$fileInfo->getSaveName();
} else {
$res = '<h3 style="color:red;">上传失败</h3>'.$file->getError();
}
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号