tp框架做留言板


首先是登錄的LoginController.class.php

代碼內容是

<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller
{
    
public function dengLu()
    {     
        if(empty($_POST)){   //判斷是不是空
            $this->show();
            }
            else{
                $a=D("yonghu");   //讀取用戶表
                $b=$_POST;
                $url=U('LiuYan/zhuYeMian');         //用u方法獲取路徑
                $m=$a->find($b[uid]);               //通過提交的密碼找表里面的密碼
                session("uid",$m[uid]);              //吧id存進session
                if($b[pwd]==$m[pwd]&&$m[pwd]!=""){
                    $this->success("登陸成功",$url);                    
                    }else{
                        $this->error("登陸失敗");
                        }                
                }        
    }
}

登錄頁面在View下面叫login文件夾下面的dengLu.html

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
<style type="text/css">
*{ font-family:微軟雅黑; padding:0px; margin:0px auto}
</style>
<body>
    <form action="__ACTION__" method="post">
    <div style=" width:370px; height:210px; background-color: #CCC; text-align:center">
    <div style="position:relative; top:30px"><h1>開發部內部留言板</h1></div>
    <br />
    <div style="position:relative; top:30px; height:40px;">用戶名:<input id="yonghuming" type="text" name="uid" /></div>
    <div style="position:relative; top:30px; left:9px; height:40px;">密碼:<input id="mima" type="text" name="pwd" /    ></div>
    <div style="position:relative; top:30px; height:40px;">
    <input type="submit" value="登錄" />
    &nbsp;    
    <input type="button" value="復位" onclick="Fuwei()"/></div>
    </form>
</div>
<script type="text/javascript">
function Fuwei()
{
    document.getElementById("yonghuming").value = "";
    document.getElementById("mima").value = "";
}
</script>
</body>
</html>

然后做一個父級的方法來驗證是不是登錄了在Controller文件夾下面建立個FuController.class.php

<?php
namespace Admin\Controller;
use Think\Controller;
class FuController extends Controller//造一個FuController類,用來判斷session值是否存在。
{
    public function __construct()//造一個構造函數
    {
        parent::__construct();
        if(session('?uid'))//判斷session是否存在,如果存在,什么也不做。
        {
            
        }
        else//如果不存在
        {
            //$url = U("Home/Login/login");
            $this->redirect("Admin/Login/dengLu",array(),1,'請登錄');//第一個參數是跳轉的地址,第二個參數是要傳的值,第三個參數是跳轉的時間,第四個參數是跳轉時的提示信息。
            exit;
        }
    }
}

做liuYanController.class.php

<?php
namespace Admin\Controller;
use Admin\Controller\FuController;
class LiuYanController extends FuController      //將Controller換成FuController
{    
    public function zhuYeMian(){        
        $aa = D("liuyan");
        $cc =session("uid");
        $nn=$aa->where("fasongren = '$cc' or jieshouren = '$cc' ")->select();        
        $this->assign("dd",$nn);
        $this->show();
        }
    public function faSong(){
        if(empty($_POST))
        {
            $this->show();
        }    
        else
        {     
            $nnn = D("liuyan");
            $ccc =session("uid");
            $bbb=$_POST;            
            if(!empty($bbb[jieshouren])&&!empty($bbb[xinxineirong])){                            
                $data[time]=date("Y-m-d H:i:s");        
                   $data[jieshouren]=$bbb[jieshouren];
                $data[xinxineirong]=$bbb[xinxineirong];
                $data[fasongren]=$ccc;
                $ff=$nnn->add($data);
            if($ff)
                    {
                $this->success("發送成功","faSong");
                    }
            else
                    {
                    $this->error("發送失敗");
                    }
                }            
            else{
                $this->error("不能為空","faSong");                
                }            
        }
        }
    public function tuiChu(){
        $aaa = session("uid",null);
        if(!session("?uid")){
            $this->success("退出成功","login/denglu");;
            }
    }
        
}

 

然后就是liuyan文件夾下面的主頁面和發送頁面zhuYeMian.html和faSong.html

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>

<body>
<a href="__CONTROLLER__/tuiChu"><input type="button" value="退出" /></a>
<a href="__CONTROLLER__/faSong"><input type="button" value="發送信息" /></a>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>發送人</td>
        <td>接收人</td>
        <td>發送時間</td>
        <td>信息內容</td>
    </tr>
    <foreach name="dd" item="v">
    <tr>
        <td>{$v.fasongren}</td>
        <td>{$v.jieshouren}</td>
        <td>{$v.time}</td>
        <td>{$v.xinxineirong}</td>
    </tr>
    
    </foreach>
    
</table>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>

<body>
<form action="__ACTION__" method="post">
<div>接收人:<input type="text" name="jieshouren" /></div>
<div>信息內容:<input type="text" name="xinxineirong" /></div>
<input type="submit" value="發送" />
</form>
<a href="__CONTROLLER__/zhuYeMian"><input type="button" value="返回主頁" /></a>
<a href="__CONTROLLER__/tuiChu"><input type="button" value="退出" /></a>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM