Thinkphp Message Board Example

Source: Internet
Author: User

Login:

Login.html

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >0px}</style>$("#btn"). Click (function(){    varUser = $ ("#user").Val (); varPass = $ ("#pass").Val (); $.Ajax ({URL: "__controller__/yanzheng",Data: {User:user,pass:pass},type: "POST",DataType: "TEXT",Success:function(data) {if(data = = "OK") {window. location.href= "__module__/main/xianshi";//__module__: Get the path where the module is located        }        }    }); });</script>
View Code

LoginController.class.php

<?phpnamespace Liuyan\controller; UseThink\controller;classLogincontrollerextendscontroller{ Public functionLogin () {$this-Show (); }         Public functionYanzheng () {/*echo "<script type= ' text/javascript ' >alert (' aaa ');</script>";*/        $n= D ("Yuangong"); $uid=$_post["User"]; $pwd=$_post["Pass"]; $sql= "Select pass from Yuangong where user= ' {$uid}‘"; $r=$n->query ($sql); //var_dump ($r [0][pass]);        if(!Empty($r[0] [Pass]) &&$r[0] [pass]==$pwd)//$r is a two-dimensional array, $r [0][pass] to remove the password (string type){session ("User",$uid);//after logging in, save session            $this->ajaxreturn ("OK", "eval");//Login successful, Ajax return OK to login.html page, do the next step        }        Else if(Empty($r[0] [Pass]) ||$r[0] [Pass]! =$pwd)//If the password is blank or the password entered does not match the password for this user name in the database, return to the login page        {            $this->redirect ("Liuyan/login/login", "Array ()", 3, "Please log in ..."); }    }}
View Code

ParentController.class.php: Intermediate transition Controller; parent::__construct (); //In the constructor add this sentence to prevent error

<?phpnamespace Liuyan\controller; UseThink\controller;classParentcontrollerextendscontroller{ Public function__construct () {Parent:: __construct ();//Add this sentence to the constructor to prevent an error        if(The session ('? User ')))        {        }        Else        {            $this->redirect (' Liuyan/login/login ',Array(), 3, ' Please login ... '); }        }    }
View Code

Main side: xianshi.html

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >0px}</style>$btn}</div><script type= "Text/javascript" >$ (document). Ready (function(e) {$.Ajax ({URL: "__controller__/yemian",Data:{},type: "POST",DataType: "JSON",Success:function(data) {varstr = "<tr><td> sender </td><td> Send time </td><td> recipient </td><td> Information Content </td ></tr> ";  for(A in data)//JSON accepts loop display data method{str+ = "<tr><td>" +data[a].sender+ "</td><td>" +data[a].times+ "</td><td>" +data[a ". recever+ "</td><td>" +data[a].comment+ "</td></tr>"; }        $("#tb").append (str) ;});</script></body>
View Code

Modification page: xiugai.html

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >0px}</style>Send Information: </div> <div> <div> <span> recipient:</span> <select id= "INP" > <foreachName= "a" item= "V" > <option>{$v.firend}</option> </foreach> </select> </div> <div> <span> information content: </span><textare A name= "comment" id= "tx" ></textarea> </div> </div> <div><input type= "button "Value=" sends "id=" BTN "/><input type=" reset "value=" reset "/></div></div><script type=" text/ JavaScript ">$("#btn"). Click (function(){varINP = $ ("#inp").Val ();vartx = $ ("#tx").Val (); $.Ajax ({URL: "__controller__/addxian",Data: {INP:INP,TX:TX},type: "POST",DataType: "TEXT",Success:function(data) {if(data = = ' OK ') {window. location.href= "__controller__/xianshi"; }    Else if(data== "No") {alert ("The content you entered cannot be empty"); }    Else{window. location.href= "__controller__/xiugai"; }    }    });});</script></body>
View Code

Master controller (display and modification): MainController.class.php

<?phpnamespace Liuyan\controller; UseLiuyan\controller\parentcontroller;classMaincontrollerextendsparentcontroller{ Public functionXianshi () {$this-Show (); }     Public functionYemian () {$n= D ("Liuyan"); $zs=$n-Count();//find the total number of data        $p=New\liuyan\fzl\page ($zs, 3); $attr=$n->limit ($p->limit)->select ();//echo $p->limit; output is 0, 2, put directly into $n->limit ()        $btndiv=$p->fpage ();//page Flip Button        $this->assign ("Btn",$btndiv);//page Turn button register to foreground display        $this->ajaxreturn ($attr); }         Public functionXiugai ()//The Publish Information page recipient drop-down list displays    {        $n= D ("Firend"); $a=$n-Select (); $this->assign ("a",$a); $this-Show (); }     Public functionAddxian ()//$data ["IDs"]: column data added to the database    {        $data["Ids"]= ""; $data["Sender"] = Session ("User")); $data["recever"] =$_post["INP"]; $data["times"] =Date("Y-m-d h:i:s"); $data["Comment"] =$_post["TX"]; $data["states"]= ""; $n= D ("Liuyan"); if(Empty($_post["INP"]) ||Empty($_post["TX"]))        {            Echo"No"; }        Else        {            $r=$n->add ($data);//Add a database            if($r)            {                Echo"OK"; }        }    }     Public functionQing ()//Click to exit the system, clear session{session (NULL); $this->redirect ("Liuyan/login/login",Array(), 0); }}
View Code

__________

Thinkphp Message Board Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.