• 夺命雷公狗TP3.2.3商城4-----管理员的创建


    首先我们来到数据库内创建一个管理员的表:

    然后我们来D:phpStudyWWWshopWEBAdminController创建Admin的控制器,

    修改内容如下所示:

    <?php
    namespace AdminController;
    use ThinkController;
    class AdminController extends Controller {
        public function lists(){
            $this -> display();
        }
    
        public function add(){
            $this -> display();
        }
        public function edit(){
            $this -> display();
        }
    
        public function del(){
            $this -> display();
        }
    }

    然后就到D:phpStudyWWWshopWEBAdminView  下抽奖一个Admin 的目录,

    然后将我们准备好的模版放进去:

    然后使用  __PUBLIC__   来改下样式   和  使用__MODULE__  来改一下跳转路径,这些都是TP默认给我们留下来的。。

     

    修改完成后来访问看看效果:

    然后开始写add的方法:

    <?php
    namespace AdminController;
    use ThinkController;
    class AdminController extends Controller {
        public function lists(){
            $this -> display();
        }
    
        public function add(){
            $mod = D("admin");
            if(IS_POST){
                $data['username'] = I('username');
                $data['password'] = I('pass');
                $data['passer'] = I('passer');
                if($data['password'] == $data['passer']){
                    if($mod->create($data)){
                        if($mod->add($data)){
                            $this -> success('管理员添加成功');
                        }else{
                            $this->error('管理员添加失败');
                        }
                    }else{
                        $this->error($mod->getError());
                    }
                }else{
                    $this->error('确认密码错误');
                }
                return;//这里的return主要是为了防止跳转
            }
            $this -> display();
        }
    
        public function edit(){
            $this -> display();
        }
    
        public function del(){
            $this -> display();
        }
    }

    由于验证我们是需要到Model  里面进行验证的,所以我们来到D:phpStudyWWWshopWEBAdminModel  目录下创建一个AdminModel.class.php

    代码如下所示:

     

    <?php
    namespace AdminController;
    use ThinkController;
    class AdminController extends Controller {
        public function lists(){
            $this -> display();
        }
    
        public function add(){
            $mod = D("admin");
            if(IS_POST){
                $data['username'] = I('username');
                $data['password'] = I('pass');
                $data['passer'] = I('passer');
                if($data['password'] == $data['passer']){
                    if($mod->create($data)){
                        if($mod->add($data)){
                            $this -> success('管理员添加成功');
                        }else{
                            $this->error('管理员添加失败');
                        }
                    }else{
                        $this->error($mod->getError());
                    }
                }else{
                    $this->error('确认密码错误');
                }
                return;//这里的return主要是为了防止跳转
            }
            $this -> display();
        }
    
        public function edit(){
            $this -> display();
        }
    
        public function del(){
            $this -> display();
        }
    }

    添加虽然成功了,但是密码还没有加密:

    然后在控制器下对她进行加密一下即可:

    <?php
    namespace AdminController;
    use ThinkController;
    class AdminController extends Controller {
        public function lists(){
            $this -> display();
        }
    
        public function add(){
            $mod = D("admin");
            if(IS_POST){
                $data['username'] = I('username');
                $data['password'] = I('pass');
                $data['passer'] = I('passer');
                if($data['password'] == $data['passer']){
                    $data['password'] = md5($data['password']);
                    if($mod->create($data)){
                        if($mod->add($data)){
                            $this -> success('管理员添加成功');
                        }else{
                            $this->error('管理员添加失败');
                        }
                    }else{
                        $this->error($mod->getError());
                    }
                }else{
                    $this->error('确认密码错误');
                }
                return;//这里的return主要是为了防止跳转
            }
            $this -> display();
        }
    
        public function edit(){
            $this -> display();
        }
    
        public function del(){
            $this -> display();
        }
    }

    然后到数据库查看下,即可发现成功加密了:

    YES,添加完美完成。。。

  • 相关阅读:
    Git常用命令清单笔记
    MySQL sql语句获取当前日期|时间|时间戳
    mysql-5.7.17.msi安装
    mysql sql语句大全
    解决Springboot集成ActivitiModel提示输入用户名密码的问题
    JAVA Spring MVC中各个filter的用法
    Spring Boot gradle 集成servlet/jsp 教程及示例
    RequireJS 参考文章
    Javascript模块化工具require.js教程
    Javascript模块化编程之路——(require.js)
  • 原文地址:https://www.cnblogs.com/leigood/p/7246420.html
Copyright © 2020-2023  润新知