tp5——实践管理员列表编辑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/iheyu/article/details/89350296
 把管理员列表分页从左边改到右边:
	1.在admin\view\admin\lst.htm 下 添加内容:
	  <div style="text-align:right;margin-top:10px;"> <!--- 注意加在外层div上面 居右 外边距上面留10个像素 --->
	  <div>
                <div style="text-align:right;margin-top:10px;">
                 {$list->render()}
	        </div>
           	 </div>
	管理员列表分页就在右边了!
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/lst

	编辑管理员列表
	2.修改连接地址,在 admin\view\admin\lst.htm 下 修改连接地址:
	  <td align="center">{$vo.id}</td>
                                <td align="center">{$vo.username}</td>
                                <td align="center">
                                    <a href="{:url('admin/edit',array('id'=>$vo['id']))}" class="btn btn-primary btn-sm shiny">
                                        <i class="fa fa-edit"></i> 编辑
                                    </a>
3.C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\controller\Admin.php 下
	   添加编辑内容,修改为:
	   public function edit(){
     	   return $this->fetch();
  	  }
   	 public function del(){
	有显示添加内容
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/5.html  

	处理界面  
	4.C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\view\admin 下
	   复制 add.html文件,重命名 edit.html文件 
	  左下角编辑链接地址正确!
	 什么都没刷出来!
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/13.html
5.C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\view\admin\edit.htm 下
	   修改内容,修改为:
	 </li>
                       <li class="active">修改管理员</li>
                       </ul>
                </div>
                <!-- /Page Breadcrumb -->

                <!-- Page Body -->
                <div class="page-body">
                    
	<div class="row">
   	 <div class="col-lg-12 col-sm-12 col-xs-12">
      	  <div class="widget">
         	   <div class="widget-header bordered-bottom bordered-blue">
              	  <span class="widget-caption">修改管理员信息</span>
           	 </div>
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/13.html
6.在wanzheng\application\admin\controller\Admin.php 下
	   添加内容:
	  // find查询一条信息,select 查询多条信息;	
	  public function edit(){
    	 // 根据id查数据
      	  $id = input('id');
   	 // 根据主键进行查询
     	   $admins = db('admin')->find($id);
      	  dump($admins);die;
       	 return $this->fetch();
   	 }
	打印出来当前管理员“id,username,password";
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/13.html

	
	7 .在wanzheng\application\admin\controller\Admin.php 下
	   内容修改为:
	   public function edit(){
    	 // 根据id查数据
       	 $id = input('id');
    	// 根据主键进行查询
        	$admins = db('admin')->find($id);
     	// 分配到模板当中
       	$this->assign('admins',$admins);
        	return $this->fetch();
   	 }
8.在 wanzheng\application\admin\view\admin\edit.htm 下
	  添加内容:
	           <label for="username" class="col-sm-2 control-label no-padding-right">管理员名</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="username" placeholder="" name="username" value="{$admins.username}" required="" type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 必填</p>
                        </div>
	刷新就会出现当前用户的管理员用户名
	http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/13.html

		
	9.在 wanzheng\application\admin\view\admin\edit.htm 下
	   修改添加隐藏区域指的是主键,内容修改:
	   <div class="form-group">
                            <input type="hidden" name="id" value="{$admins.id}"><!---当前管理员要修改的主键,根据主键知道修改管理员--->
                            <label for="username" class="col-sm-2 control-label no-padding-right">管理员名</label>
10.在wanzheng\application\admin\controller\Admin.php 下
	     执行修改操作,内容修改:
	      public function edit(){
                      // 如果有返回来的数据就以数组的形式接收
       	     if(request()->isPost()){  //判断是否由Post表单提交过来
         	     $data=[
             		    'id'=>input('id'),
             		    'username'=>input('username'),//前面username的和数据表里数据对应,后面username和表单里的name值数据对应
            		    'password'=>input('password'),
        		];
        		 dump($data);die; // 看看是否能提交过来打印的数据
       		  return;
     		   }
		打印出来id,username,password以数组的形式!
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/7.html
	

		11.在 wanzheng\application\admin\controller\Admin.php 下
		     内容修改为:	
		     public function edit(){
    		    // 如果有返回来的数据就以数组的形式接收
      		    if(request()->isPost()){
           		    $data=[
          		            'id'=>input('id'),
            		 	    'username'=>input('username'),//前面username的和数据表里数据对应,后面	username和表单里的数据对应
              		         'password'=>input('password'),
      			           ];
			    dump($data);die;
			    return;
		        $id = input('id');
      		    // 根据主键进行查询
      		    $admins = db('admin')->find($id);
       		     // 分配到模板当中
       		     $this->assign('admins',$admins);
      		     return $this->fetch();

		打印出来$data,里面的值;	
		 http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/12.html

		12.在 wanzheng\application\admin\controller\Admin.php 下
		    执行修改操作,内容修改为:
		    public function edit(){
		    $id =input('id');
		    $admins = db('admin')->find($id);	
    		    // 如果有返回来的数据就以数组的形式接收
      		    if(request()->isPost()){
           		    $data=[
          		          'id'=>input('id'),
            		 	  'username'=>input('username'),//前面username的和数据表里数据对应,后面username和表单里的数据对应
              		      'password'=>input('password'),
      			   ];
       		    if(db('admin')->update($data)){ // 数据库里对应表->更新数据表里的数据
            		        $this->success("修改管理员成功!","lst");
              		    }else{
            		        $this->error("修改管理员失败!");
           		     }
       		  return;
       		    }
		     $id = input('id');
        	 // 根据主键进行查询
       		 $admins = db('admin')->find($id);
       		 // 分配到模板当中
      		$this->assign('admins',$admins);
     		return $this->fetch();
	
		修改管理员成功!
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/7.html
密码为空,则保持原来的密码不变	
		13.在application\admin\view\admin\edit.htm 下
		    添加内容:
		   <div class="form-group">
                            <label for="group_id" class="col-sm-2 control-label no-padding-right">管理员密码</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="password" placeholder="" name="password" required="" type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 留空则表示不修改密码</p>
                        </div> 
	      http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/7.html
   14.在 wanzheng\application\admin\view\admin\edit.htm下
	            添加验证,内容修改为:
	            public function edit(){
       		 $id =input('id');
      		  $admins = db('admin')->find($id);
      		  // 如果有返回来的数据就以数组的形式接收
      		  if(request()->isPost()) {
        		    $data = [
               			 'id' => input('id'),
              			  'username' => input('username'),//前面username的和数据表里数据对应,后面username和表单里的数据对应
        			    ];
         		   if (input('password')) {
               		       $data['password'] => md5(input('password'));
          		  } else {
               		      $data['password'] => $admins['password'];
        		    }
         
              		  if (db('admin')->update($data)) {
                 	          $this->success("修改管理员成功!", "lst");
             		   } else {
                 	         $this->error("修改管理员失败!");
            		    }
              		  return;
           		 }
          		  $this->assign('admins', $admins);
           		 return $this->fetch();
      		  }

	**********************************************************************************************************************
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/lst.html
	  	 语法错误: unexpected '=>' (T_DOUBLE_ARROW) (bug)
		 if (input('password')) {
               			 $data['password'] =md5(input('password'));
          		  } else {
              			  $data['password'] =$admins['password'];
        		    }
		刷新修改都可以!
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/15.html
****************************************************************************************************************************
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/3.html
		1.只修改"管理员名",“管理员密码,留空表示密码不变",管理员密码留空;
		2.点击"保存信息",显示"请填写此字段";
		实现不了"留空则表示不修改密码"(bug);

		C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\view\admin\edit.htm
		把原内容:
	          <div class="form-group">
                            <label for="group_id" class="col-sm-2 control-label no-padding-right">管理员密码</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="password" placeholder="" name="password" required="" type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 留空则表示不修改密码</p>
                        </div> 
		修改为:	
		<div class="form-group">
                            <label for="group_id" class="col-sm-2 control-label no-padding-right">管理员密码</label>
                            <div class="col-sm-6">
                                <input class="form-control" id="password" placeholder="" name="password"  type="text">
                            </div>
                            <p class="help-block col-sm-4 red">* 留空则表示不修改密码</p>
                        </div>
 
		去掉:<input class="form-control" id="password" placeholder="" name="password" required="" type="text">
		的  required="" 字段	就实现了"留空则表示不修改密码"!
****************************************************************************************************************************

		执行验证:
		15.在wanzheng\application\admin\controller\Admin.php 下
		添加验证,修改内容为:
		if(input('password')){
          		$data['password']=md5(input('password'));
     		 }else{
        		  $data['password']=$admins['password'];
     		 }
        		$validate = \think\Loader::validate('Admin');
         		 if (!$validate->scene('edit')->check($data)) {
             		 $this->error($validate->getError()); 
             		 die;
         		 }
    		 if(db('admin')->update($data)){
       		     $this->success("修改管理员成功!","lst");
   		  }else{
       		      $this->error("修改管理员失败!");
 		    }
  		   return;
   		   }
     		  $this->assign('admins',$admins);
     		  return $this->fetch();
     		  }

		16.在 WWW\wanzheng\application\admin\validate\Admin.php 下
		    添加内容,修改为:
		  protected $scene =[
 				 'add'=>['username'=>'require','password'],
 				 'edit'=>['username'=>'require','password'],
			];

	 	17.要验证密码不能为空:
		    C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\controller\Admin.php
		   原内容:
			public function edit()
  			  {
      			  $id = input('id');
      			  $admins = db('admin')->find($id);
    			  if(request()->isPost()){
    			        $data=[
        				     'id'=>input('id'),
        				     'username'=>input('username'),
     				    ];
     			 if(input('password')){
        			       $data['password']=md5(input('password'));
     			  }else{
         			       $data['password']=$admins['password'];
  			    }
      			$validate = \think\Loader::validate('Admin');
        			 if (!$validate->scene('edit')->check($data)) {
            			 $this->error($validate->getError());
            			 die;
       			   }
	                 修改为:

			if(input('password')){
        			       $data['password']=input('password');
     			  }else{
         			      // $data['password']=$admins['password'];
  			    }
      			$validate = \think\Loader::validate('Admin');
        			 if (!$validate->scene('edit')->check($data)) {
            			 $this->error($validate->getError());
            			 die;
       			   }
		只修改"管理员名"不修改"管理员密码",验证到“管理员密码必须填写”!
		http://www.iheyu.com/wanzheng/public/index.php/admin/admin/edit/id/10.html

		18.在 WWW\wanzheng\application\admin\validate\Admin.php 下
		    不需要验证管理员密码,修改为:
		  protected $scene =[
 				 'add'=>['username'=>'require','password'],
 				 'edit'=>['username'=>'require'],
			];
		C:\phpStudy\PHPTutorial\WWW\wanzheng\application\admin\controller\Admin.php
		   改回来:
		   if(input('password')){
        			       $data['password']=md5(input('password'));
     			  }else{
         			      $data['password']=$admins['password'];
  			    }

猜你喜欢

转载自blog.csdn.net/iheyu/article/details/89350296
tp5