这个是项目的开发过程的第一天,简单说一下,这个项目是有点类似百度百科的项目,功能主要是可以发布百科关键词和进行编辑等,还有参考网站来源,基本该有的百科的网站功能都实现了,项目可以支持电脑版,和手机版的,采用了我们比较主流又容易接受的开发模式,PHP+MySQL。
这个是后台功能部分的代码
class AdminController extends ParentController{
public function __construct(){
parent::__construct();
$this->data = D('Admin/data');
$this->Admin = D('Admin');
}
public function index(){
$id = I('get.del',0,'intval');
$getCount = $this->data->get_count('nav_admin',1);
$Page = new Page($getCount,8);
$Page->rollPage = 8;
$Page->lastSuffix = false;
$Page->setConfig('first','首页');
$Page->setConfig('last','尾页');
$Page->setConfig('prev','<<');
$Page->setConfig('next','>>');
$this->showPage = $Page->show();
//根据分页参数获取列表页的数据
$this->admin=$this->data->get_limit('nav_admin',1,'*','addtime DESC',$Page->firstRow,$Page->listRows);
$this->display('list');
}
//删除
public function delete_phome(){
$id = (int)$_GET['cid'];
$res = $this->data->get_all('nav_admin',"userid=$id");
$this->data->delete('nav_admin',"userid='$id'");
echo json_encode(1);
}
public function add(){
if(IS_POST){
if(!$this->Admin->create()){
$this->error('添加失败!!!'.$this->Admin->getError());die;
}else{
$this->Admin->add();
$this->success('添加成功!!!',U('Admin/index'));die;
}
}
$this->display();
}
查询数据
public function edit(){
$id = I('get.cid',0,'intval');
$this->query = $this->data->get_one('nav_admin',"$id=userid");
$this->display();
}
public function edit_action(){
if(IS_POST){
$id = (int)$_POST['cid'];
$data['username'] = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$password1 = htmlspecialchars($_POST['password2']);
if($password!=$password1){
$this->error('两次密码不一致!!!'.$this->Admin->getError());die;
}
if($password){
$user=$this->data->get_one('nav_admin',"userid=$id");
$data['password']=sha1(substr(md5($password.$user['salt']), 0,20).$user['salt']);
}
$statu=$this->data->update('nav_admin',"userid=$id",$data);
if(!$statu){
$this->error('修改失败!'.$this->Admin->getError());die;
}else{
$this->success('修改成功!!!',U('Admin/index'));die;
}
}
}
public function login(){
if( session('is_login') ){
$this->success('您已成功登录!',U('Admin/index'));die;
}
$this->display();
}
退出登录与登录
public function logout(){
session(null);
$this->success('退出登录成功!',U('Admin/login'));
}
public function checkLogin(){
//接受数据
if(IS_POST){
$username = I('post.username','','htmlspecialchars');
$password = I('post.password','','htmlspecialchars');
$code = I('post.code');
//校验验证码
$verify = new \Think\Verify();
if(!$verify->check($code)){
$this->error('验证码有误,请重新输入');die;
}
//验证账号
$info = $this->Admin->field()->where("username = '$username'")->find();
if(!$info){
$this->error('该用户账号不存在!或者为空');die;
}
//验证密码
$password = $this->Admin->encrypt($password,$info['salt']);
if( $password != $info['password'] ){
$this->error('密码错误!');die;
}
$user = session('username',$username);
session('is_login',1);
$this->success('登录成功!',U('index/index'));die;
}
}
//验证码
public function Verify(){
$config = array(
'fontSize' => 48, // 验证码字体大小
'length' => 4, // 验证码位数
'useNoise' => true, // 关闭验证码杂点
);
$Verify = new \Think\Verify( $config );
$Verify->entry();
}