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

首先咱们来到数据库内建立一个管理员的表:php

 

 

而后咱们来D:\phpStudy\WWW\shop\WEB\Admin\Controller建立Admin的控制器,数据库

修改内容以下所示:this

<?php
namespace Admin\Controller;
use Think\Controller;
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:\phpStudy\WWW\shop\WEB\Admin\View  下抽奖一个Admin 的目录,加密

而后将咱们准备好的模版放进去:spa

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

 

 

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

 

而后开始写add的方法:blog

<?php
namespace Admin\Controller;
use Think\Controller;
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:\phpStudy\WWW\shop\WEB\Admin\Model  目录下建立一个AdminModel.class.phpmd5

 

代码以下所示:get

 

<?php
namespace Admin\Controller;
use Think\Controller;
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 Admin\Controller;
use Think\Controller;
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,添加完美完成。。。

相关文章
相关标签/搜索