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>

     <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时间插件的使用

 

 

 

 

前台代码

<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');
                        });
            });

$.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>

  

 

后台代码

<?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);
    }





}

  

 

posted @ 2017-06-22 21:21  hao_1234_1234  阅读(385)  评论(0编辑  收藏  举报