tp5判断是否登录 2020-04-03 技术分享,PHP学习资料 4 条评论 1275 次阅读 tp5是什么?全民为**ThinkPHP** ThinkPHP是一个免费开源的,快速、简单的面向对象的轻量级PHP开发框架,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。遵循Apache2开源许可协议发布,意味着你可以免费使用ThinkPHP,甚至允许把你基于ThinkPHP开发的应用开源或商业产品发布/销售。  在Controller控制器下新建`Common.php` ```php error('请先登录!',url('/admin/login/index')); } } } ``` 在需要判断登录的类中继承该类: `Index.php` ```php param(); $name = input('tid') ? input('title') : ($sou['title'] = ''); //判断是不是第一栏目 $t_fid = input('t_fid') ? input('t_fid') : 0; $Z_tid = 2; if(isset($_POST['sousuo'])){ $tid = input("tid"); $title = input("title"); $data = array(); if(!empty($tid)){ $data['a.tid'] = $tid; } if(!empty($title)){ $data['title'] = ['like','%'.$title.'%']; } $arr=Db::table('article') ->alias('a') ->join('type t','a.tid=t.tid') ->field('a.*,t.tname')//查询指定字段 ->where('a.tid','neq',$Z_tid) ->where($data) ->group('a.id')//分组 ->paginate(5, false, ['query' => request()->param()]);//分页 $page=$arr->render(); $tid = Db::name('type')->select(); return view("list",['arr'=>$arr,'tid'=>$tid,'page'=>$page,'title'=>$title]); }else{ $arr=Db::table('article') ->alias('a') ->join('type t','a.tid=t.tid') ->field('a.*,t.tname')//查询指定字段 ->where('a.tid','neq',$Z_tid) ->order("id desc") ->group('a.id')//分组 ->paginate(5, false, ['query' => request()->param()]);//分页 $page=$arr->render(); $tid = Db::name('type') ->where('tid','neq',$Z_tid)->select(); return view("list",['arr'=>$arr,'tid'=>$tid,'page'=>$page,'title'=>""]); } } /** * 文章类型删除 */ public function type_delete(){ $id=$_GET['id']; $rs=Db::table('type')->where('tid',$id)->delete(); if($rs) { $this->success('删除成功','admin/Index/typeContent');} else { $this->error('删除失败','admin/Index/typeContent');} } /** * 文章类型修改 */ public function type_update() { $id = input('tid'); if (isset($_POST['sub'])) { $tname = input("tname"); $xiugai = Db::name('type') ->where('tid', $id) ->update(['tname' => $tname]); if ($xiugai) $this->success('修改成功', 'admin/Index/typeContent'); else $this->error('修改失败', 'admin/Index/typeContent'); }else{ $id = input('id'); $array = Db::name('type')->where('tid',$id)->find(); return view("type_update",['arr'=>$array]); } } } ``` 在不需要判断是否登录的类中不继承该类,继承Controller就行: `Login.php` ```php where('uname',$name) ->where('upwd',$pwd) ->find(); if($user) { Session::set('uname',$name); $this->success('登陆成功','admin/Index/index'); } else { $this->error('用户名或密码错误','index'); } }else{ return view('login'); } } function dieLogin() { Session(null); return view('login'); } } ``` 打赏: 微信, 支付宝 标签: tp5判断是否登录 本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
Very nice article. I absolutely love this site.
Continue the good work!
Very descriptive blog, I enjoyed that a lot. Will there be a part 2?
This article is in fact a fastidious one it helps new internet
visitors, who are wishing for blogging.
I've read several just right stuff here. Definitely worth bookmarking for revisiting.
I wonder how a lot attempt you set to make this type of wonderful informative web site.