abstrak:<?php /** * Created by PhpStorm. * User: 普通用戶 * Date: 2019/5/13 * Time: 0:14 */ namespace app\admin\controller; sess
<?php /** * Created by PhpStorm. * User: 普通用戶 * Date: 2019/5/13 * Time: 0:14 */ namespace app\admin\controller; session_start(); use app\model\User; use pig\core\Controller; class Index extends Controller { public function __construct() { parent::__construct(); } public function index() { $rows = (new User())->select('user',['uid','name','phone','country','birthday','weight', 'height','add_time']); return $this->view->render('admin::index/index',['title'=>'演員管理系統(tǒng)', 'rows'=>$rows, 'loginUrl'=>'/admin/index/login', 'logoutUrl'=>'/admin/index/logout', 'indexUrl'=>'/admin/index/index', 'insUrl'=>'/admin/index/insert', 'editUrl'=>'/admin/index/edit', 'delUrl'=>'admin/index/delete', 'findUrl'=>'admin/index/find' ]); } public function login() { if($_SERVER['REQUEST_METHOD'] == 'POST'){ $res=(new User)->get('admin',['email','password','name'],[ 'AND'=>[ 'email'=>$_POST['email'], 'password'=>sha1($_POST['password']), ] ]); if (false===$res){ echo "<script>alert('郵箱或密碼不正確');location.href='/';</script>"; }else{ $_SESSION['name']=$res['name']; echo "<script>alert('登陸成功');location.href='/';</script>"; } } } public function logout() { session_destroy(); echo "<script>alert('退出成功');location.href='/';</script>"; } public function insert() { return $this->view->render('admin::index/insert',[ 'title' =>'添加成員', 'url'=>'/admin/index/add' ]); } public function add() { if($_SERVER['REQUEST_METHOD'] == 'POST') { (new User)->insert('user',[ 'name'=>$_POST['name'], 'phone'=>$_POST['phone'], 'country'=>$_POST['country'], 'birthday'=>$_POST['birthday'], 'weight'=>$_POST['weight'], 'height'=>$_POST['height'], 'add_time'=>strtotime($_POST['add_time']) ]); echo "<script>alert('添加成功');location.href='/';</script>"; } } public function edit($uid='') { $row=(new User())->get('user',[ 'uid','name','phone','country','birthday','weight','height','height','add_time'],['uid'=>$uid]); return $this->view->render('admin::index/edit',[ 'title'=>'修改用戶', 'url'=>'/admin/index/save', 'row'=> $row ]); } public function save($uid='') { if($_SERVER['REQUEST_METHOD']=='POST'){ (new User())->update('user',[ 'name'=>$_POST['name'], 'phone'=>$_POST['phone'], 'country'=>$_POST['country'], 'birthday'=>$_POST['birthday'], 'weight'=>$_POST['weight'], 'height'=>$_POST['height'], 'add_time'=>strtotime($_POST['add_time']) ],['uid'=>$uid]); } echo "<script>alert('更新成功');location.href='/';</script>"; } public function delete($id) { $ret= (new User())->delete('user',['uid' => $id]); if($ret){ echo "<script>alert('刪除成功');location.href='/';</script>"; }else{ echo "<script>alert('刪除失敗');location.href='/';</script>"; } } public function find() { $find=$_POST['find']; $find_val=$_POST['find_val']; $rows = (new User())->select('user',['uid','name','phone','country','birthday','weight', 'height','add_time'],[$find => $find_val]); if(!count($rows)) { echo "<script>alert('找不到您需要的信息');location.href='/';</script>"; } return $this->view->render('admin::index/index',['title'=>'演員管理系統(tǒng)', 'rows'=>$rows, 'loginUrl'=>'/admin/index/login', 'logoutUrl'=>'/admin/index/logout', 'indexUrl'=>'/admin/index/index', 'insUrl'=>'/admin/index/insert', 'editUrl'=>'/admin/index/edit', 'delUrl'=>'admin/index/delete', 'findUrl'=>'admin/index/find' ]); } }
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title><?=$this->e($title);?></title> <link rel="stylesheet" href="/static/stytle.css"> </head> <body> <?php if(isset($_SESSION['name']) && $_SESSION['name'] =='admin'):?> <p>歡迎管理員: <?=$this->e($_SESSION['name'])?> | <a href="<?=$this->e($logoutUrl);?>">退出</a></p> <?php else:?> <form action="<?=$this->e($loginUrl);?>" method="post"> 用戶名:<input type="email" name="email" placeholder="請輸入郵箱"> 密碼:<input type="password" name="password" placeholder="請輸入密碼"> <input type="submit" value="登錄"> </form> <?php endif;?> <table > <caption><h2>人員信息登記表 </h2> <?php if(isset($_SESSION['name']) && $_SESSION['name'] =='admin'):?> <a href="<?=$this->e($insUrl);?>" style="background: #ccc;">添加用戶</a> <?php endif;?> </caption> <tr> <th>工號</th> <th>姓名</th> <th>聯(lián)系電話</th> <th>國籍</th> <th>出生日期</th> <th>體重</th> <th>身高</th> <th>入職時間</th> <?php if(isset($_SESSION['name']) && $_SESSION['name'] =='admin'):?> <th>操作</th> <?php endif;?> </tr> <?php foreach ($rows as $row):?> <tr> <td><?=$this->e($row['uid']);?></td> <td><?=$this->e($row['name']);?></td> <td><?=$this->e($row['phone']);?></td> <td><?=$this->e($row['country']);?></td> <td><?=$this->e($row['birthday']);?></td> <td><?=$this->e($row['weight']);?></td> <td><?=$this->e($row['height']);?></td> <td><?=$this->e(date("Y-m-d",$row['add_time']));?></td> <?php if(isset($_SESSION['name']) && $_SESSION['name'] =='admin'):?> <td><a href="<?=$this->e($editUrl)?>/id/<?=$this->e($row['uid']);?>">修改</a> <a href="javascript:;" onclick="del(<?=$this->e($row['uid']);?>)" style="color: red;return false">刪除</a></td> <?php endif;?> </tr> <?php endforeach;?> </table> <form action="<?=$this->e($findUrl)?>" style="height: 100px;" method="post"> 搜索: <input type="text" name="find_val" placeholder="請輸入要搜索的條件" value=""> <select name="find"> <option value ="uid">工號</option> <option value ="name">姓名</option> <option value ="phone">聯(lián)系電話</option> <option value ="country">國籍</option> <option value ="birthday">出生日期</option> <option value ="weight">體重</option> <option value ="height">身高</option> <option value ="add_time">入職日期</option> </select> <input type="submit"value="開始搜索"> </form> <script> function del(id) { if(confirm("是否刪除 id="+id+"的記錄")){ location.href='/admin/index/delete/id/'+id; } } </script> </body> </html>
經(jīng)過本章節(jié)對框架的編寫開發(fā),對mvc模式有一定的理解,從框架基礎類,參數(shù)解析分發(fā)到模塊實例化,模版渲染等知識的學習。后繼課外再繼續(xù)重復練習爭取更加鞏固下一階段的thinkphp 開發(fā)技能。
Guru membetulkan:查無此人Masa pembetulan:2019-05-14 09:13:46
Rumusan guru:完成的不錯。框架的作用非常大,特別是開發(fā)大型項目,能減少很多工作。繼續(xù)加油。