thinkphp 网址后台典型页面
知识点:
1.select
a提交后 返回选中项
选中项 value是id 但是要显示name
b遍历和列举两种形式
<select name="class_id" class="left">
<option value="">不限</option>
<volist name="advertise_class" id="vo">
<eq name="vo.id" value="$map.class_id">
<option value="{$vo.id}" selected >{$vo.name}</option>
<else />
<option value="{$vo.id}" >{$vo.name}</option>
</eq>
</volist>
</select>
1 2 3 4 5 | < select name= "sex" class = "pull-left" > <option value= "" >不限</option> <option value= "1" <?php if ($map[ 'sex' ] == '1' ):?>selected= "selected" <?php endif;?> >男</option> <option value= "0" <?php if ($map[ 'sex' ] == '0' ):?>selected= "selected" <?php endif;?> >女</option> </ select > |
2 分页 两种实现方式
方式二
//总页数
$total = $this->adminObj->where($where)->count();
$Page = new \Think\Pages($total, 10);
$data = $this->adminObj->where($where)->limit($Page->first, $Page->listRows)->order('id desc')->select();
$this->assign('page', $Page->show());
3 连表查询,把id转为name
4时间插件的使用
前台代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | <extend name= "Public/base" /> { // 导航} <block name= "breadcrumb" > <li class = "active" >求职者管理</li> </block> { // 左侧菜单} <block name= "sidebar" > <include file= "Public/sidebar" nav= "jobSeeker" /> </block> { // 主体} <block name= "main" > <div class = "row-fluid" > <h3 class = "header blue lighter smaller" > <form action= "{:U('Admin/JobSeeker/index')}" method= "get" > <div class = "row-fluid dataTables_wrapper" > <!--<div class = "span4" >--> <!--<a class = "btn btn-primary btn-small" href= "{:U('Admin/JobSeeker/add')}" target= "_blank" ><i class = "icon-plus" ></i>添加</a>--> <!--</div>--> <div class = "grid_conent" id= "m_search_div" > <div class = "grid" > <label class = "control-label pull-left" >用户名:</label> <input name= "username" value= "{$map.username}" type= "text" id= "search_name" class = "pull-left" /> </div> <div class = "grid" > <label class = "control-label pull-left" >地点:</label> < select name= "address" class = "pull-left" > <option value= "" >不限</option> <volist name= "city_class" id= "vo" > <eq name= "vo.id" value= "$map.address" > <option value= "{$vo.id}" selected >{$vo.name}</option> < else /> <option value= "{$vo.id}" >{$vo.name}</option> </eq> </volist> </ select > </div> <div class = "grid" style= " width: auto;" > <label class = "control-label pull-left" >性别:</label> < select name= "sex" class = "pull-left" > <option value= "" >不限</option> <option value= "1" <?php if ($map[ 'sex' ] == '1' ):?>selected= "selected" <?php endif;?> >男</option> <option value= "0" <?php if ($map[ 'sex' ] == '0' ):?>selected= "selected" <?php endif;?> >女</option> </ select > </div> <div style= "width:auto; float: right; " ><button type= "submit" class = "btn btn-primary btn-small pull-left" id= "search_submit" ><i ></i>搜索</button></div> <div class = "grid_data" style= "margin: 0px 0px 0px 13px;" > <input type= "text" name= "datetimeEnd" id= "datetimeEnd" value= "{$map.datetimeEnd}" placeholder= "请选择结束日期" class = "pull-right" /> <input type= "text" name= "datetimeStart" id= "datetimeStart" value= "{$map.datetimeStart}" placeholder= "请选择开始日期" class = "pull-right" /> <label class = "control-label pull-right" >日期:</label> </div> </div> </div> </form> </h3> <div class = "table-header" >求职者管理</div> <div class = "dataTables_wrapper" role= "grid" > <table id= "user_table" class = "table table-striped table-bordered table-hover" style= "margin-bottom:0px;" > <thead> <tr> <th class = "center" > <label> <input type= "checkbox" class = "ace" /> <span class = "lbl" ></span> </label> </th> <th>用户名</th> <th>姓名</th> <th>性别</th> <th>email</th> <th>地点</th> <th>推荐人才</th> <th>热门人才</th> <th>顶级人才</th> <th>注册时间</th> <th>操作</th> </tr> </thead> <tbody> < foreach name= "data" item= "value" > <tr> <td class = "center" > <label> <input type= "checkbox" class = "ace" /> <span class = "lbl" ></span> </label> </td> <td>{$value.username}</td> <td>{$value.name}</td> <td>< if condition= "$value.sex eq 0" >女<elseif condition= "$value.sex eq 1" />男</ if ></td> <td>{$value.email}</td> <td>{$value.address}</td> <td> <a href= "javascript:;" onclick= "$.recommend_change('{:U('Admin/JobSeeker/recommend_change', array('id'=>$value['id'],'recommend'=>$value['recommend']))}');" class = "green" ><eq name= "value.recommend" value= "0" ><img src= "__PUBLIC__/HomeStyle/images/img/no.png" />< else /><img src= "__PUBLIC__/HomeStyle/images/img/yes.png" /></eq> </a></td> <td> <a href= "javascript:;" onclick= "$.hot_change('{:U('Admin/JobSeeker/hot_change', array('id'=>$value['id'],'hot'=>$value['hot']))}');" ><eq name= "value.hot" value= "0" ><img src= "__PUBLIC__/HomeStyle/images/img/no.png" />< else /><img src= "__PUBLIC__/HomeStyle/images/img/yes.png" /></eq> </a></td> <td> <a href= "javascript:;" onclick= "$.top_change('{:U('Admin/JobSeeker/top_change', array('id'=>$value['id'],'top'=>$value['top']))}');" ><eq name= "value.top" value= "0" ><img src= "__PUBLIC__/HomeStyle/images/img/no.png" />< else /><img src= "__PUBLIC__/HomeStyle/images/img/yes.png" /></eq> </a></td> <td>{$value.create_time|date= 'Y-m-d' ,###}</td> <td> <div class = "hidden-phone visible-desktop action-buttons" > <!--<a href= "{:U('Admin/JobSeeker/edit', array('id'=>$value['id']))}" class = "green" data-rel= "tooltip" data-original-title= "修改" >--> <!--<i class = "icon-pencil bigger-130" ></i>--> <!--</a>--> <a href= "javascript:;" onclick= "$.del('{:U('Admin/JobSeeker/del', array('id'=>$value['id']))}');" class = "red" data-rel= "tooltip" data-original-title= "删除" > <i class = "icon-trash bigger-130" ></i> </a> </div> </td> </tr> </ foreach > </tbody> </table> <!-- 分页 --> <div class = "row-fluid" > <div class = "page" >{$page}</div> </div> </div> </div> <p>推荐职位或热门职位√表示是,×表示否,点击取反。</p> </block> { // js} <block name= "js" > <link rel= "stylesheet" href= "__PUBLIC__/Assets/css/datepicker.css" > <script src= "__PUBLIC__/Assets/js/date-time/bootstrap-datepicker.min.js" ></script> <script src= "__PUBLIC__/Assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js" ></script> <script type= "text/javascript" > //通过id选择器 $( "#datetimeStart" ).datepicker({ format: 'yyyy-mm-dd' , //格式 language: 'zh-CN' , //语言 autoclose: true //选择后自动隐藏日历框 }); $( "#datetimeEnd" ).datepicker({ format: 'yyyy-mm-dd' , language: 'zh-CN' , autoclose: true }); </script> <script type= "text/javascript" > jQuery(function($) { // 全选框 $( 'table th input:checkbox' ). on ( 'click' , function(){ var that = this ; $( this ).closest( 'table' ).find( 'tr > td:first-child input:checkbox' ) .each(function(){ this . checked = that. checked ; $( this ).closest( 'tr' ).toggleClass( 'selected' ); }); });<br><br> $.extend({ action : function(url, obj) { var obj = $(obj).parents( 'form' ); $.ajax({ url : url, type : 'get' , data : obj.serialize(), success : function(res) { $.lagou.alert(res.msg, res.code, 2); $.lagou.formHide(); location.reload(); } }); }, //删除 del : function(url) { $.lagou.confirm( '确认删除么' , function(res){ if (res) { $. get (url, function(response){ $.lagou.alert(response.msg, response.code, 2); location.reload(); }); } }); }, //推荐人才改变事件 recommend_change : function(url) { $. get (url, function(response){ $.lagou.alert(response.msg, response.code, 2); location.reload(); }); }, //热门人才改变事件 hot_change : function(url) { $. get (url, function(response){ $.lagou.alert(response.msg, response.code,2); location.reload(); }); }, //顶级人才改变事件 top_change : function(url) { $. get (url, function(response){ $.lagou.alert(response.msg, response.code,2); location.reload(); }); } }); }) </script> </block> |
后台代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | <?php /**求职者管理 * Created by PhpStorm. * User: Administrator * Date: 2017/4/27 * Time: 13:58 */ namespace Admin\Controller; class JobSeekerController extends BaseController { protected $usersModel = null ; protected $cityModel= null ; public function __construct() { parent::__construct(); $ this ->usersModel = M( 'Users' ); //下拉列表 $ this ->cityModel=M( 'CityCategory' ); } public function index() { // //获取页面中所有name标签的内容 // $map=I(); // //移除$map中所有可以转为false的值,如:false,0,‘0’,arrary(),null,'', // $a=$map;//array_filter($map); $a=I(); ///搜索条件 //用户名 if (!empty($a[ 'username' ])){ $ where [ 'username' ]=array( 'LIKE' , '%' .$a[ 'username' ]. '%' ); } //地点 if (!empty($a[ 'address' ])){ $ where [ 'address' ]=array( 'EQ' ,$a[ 'address' ]); } //性别 if ($a[ 'sex' ]!= "" ){ $ where [ 'sex' ]=array( 'EQ' ,$a[ 'sex' ]); } //起止时间 if (!empty($a[ 'datetimeStart' ])|| !empty($a[ 'datetimeEnd' ])){ $start= strtotime($a[ 'datetimeStart' ]); $end= strtotime($a[ 'datetimeEnd' ]); $ where [ 'create_time' ]=array(array( 'egt' ,$start),array( 'elt' ,$end), 'and' ); //var_dump($where['create_time']); } //分页 $total=$ this ->usersModel-> where ($ where )->count(); $Page= new \Think\Pages($total,10); $Page->setConfig( 'first' , '首页' ); $Page->setConfig( 'prev' , '上一页' ); $Page->setConfig( 'next' , '下一页' ); $Page->setConfig( 'last' , '尾页' ); $show = $Page->show(); //搜索结果 $data=$ this ->usersModel-> where ($ where )->page(I( 'get.p' ,1),10)->order( 'create_time desc' )-> join ( 'as u left join lg_city_category as city on u.address=city.id ' )->field( 'u.id,u.username,u.name,u.sex,u.email,u.recommend,u.hot,u.top,u.create_time,city.name as address' )-> select (); //加载下拉列表 $city_category=$ this ->cityModel-> select (); //输出到模板 //下拉列表 $ this ->assign( 'city_class' ,$city_category); //其他 $ this ->assign( 'map' ,$a); $ this ->assign( 'page' ,$show); $ this ->assign( 'data' , $data); $ this ->display(); } public function details() { $data[ 'id' ] = I( 'get.id' ); $users = $ this ->usersModel-> where ($data)->find(); $cate = Category::getInstance(); $type = $cate->getParent($users[ 'name' ]); // $company = $this->comObj->where(array('id'=>$this->uid))->find(); $ this ->assign( 'category' , $cate->mCategory); $ this ->assign( 'users' , $users); $ this ->assign( 'type' , $type); // $this->assign('company', $company); $ this ->display(); } public function del(){ $id = I( 'get.id' ); // $id = $_GET['id']; //同上 $rs = $ this ->usersModel-> where ( 'id=' .$id)->delete(); if ($rs==0||$rs=== false ) { $msg[ 'code' ] = 0; $msg[ 'msg' ] = '删除失败' ; } else { $msg[ 'code' ] = 1; $msg[ 'msg' ] = '删除成功' ; } $ this ->ajaxReturn($msg); } //推荐人才改变事件,如果是则改为否,否则改为是 public function recommend_change() { if (IS_AJAX) { $id = I( 'get.id' ); $recommend = I( 'get.recommend' ); if ($recommend == 0) { $data[ 'recommend' ] = 1; } else { $data[ 'recommend' ] = 0; } $res = $ this ->usersModel-> where ( 'id=' . $id)->save($data); if ($res === false ) { $msg[ 'code' ] = 0; $msg[ 'msg' ] = '操作失败 ' ; } else { $msg[ 'code' ] = 1; $msg[ 'msg' ] = '操作成功' ; } $ this ->ajaxReturn($msg); } } //热门人才改变事件,如果是则改为否,否则改为是 public function hot_change(){ if (IS_AJAX){ $id = I( 'get.id' ); $recommend=I( 'get.hot' ); if ($recommend==0){ $data[ 'hot' ]=1; } else { $data[ 'hot' ]=0; } $res = $ this ->usersModel-> where ( 'id=' .$id)->save($data); if ($res=== false ){ $msg[ 'code' ] = 0; $msg[ 'msg' ] = '操作失败' ; } else { $msg[ 'code' ] = 1; $msg[ 'msg' ] = '操作成功' ; } $ this ->ajaxReturn($msg); } } //顶级人才改变事件,如果是则改为否,否则改为是 public function top_change(){ $id = I( 'get.id' ); $top=I( 'get.top' ); if ($top==0){ $data[ 'top' ]=1; } else { $data[ 'top' ]=0; } $res = $ this ->usersModel-> where ( 'id=' .$id)->save($data); if ($res=== false ){ $msg[ 'code' ] = 0; $msg[ 'msg' ] = '操作失败' ; } else { $msg[ 'code' ] = 1; $msg[ 'msg' ] = '操作成功' ; } $ this ->ajaxReturn($msg); } } |
树立目标,保持活力,gogogo!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具