This paper describes the method of message board based on thinkphp framework. Share to everyone for your reference, as follows:
Struggle for a day, finally thinkphp Little Deng message version of the concept version came out
In fact, really thinkphp development speed, as an internet "move Brick", engaged in this pure code farming is understandable.
The code implements the following functions
1. Message function.
2. Verify the function.
3. pagination display function.
is to write a few lines of code (PS: Page design Code does not count, even if the controller and model Code)
Below I publish the control of the code, about thinkphp code rules I will not elaborate, look at the thinkphp manual can be.
Class Indexaction extends action{public Function index () {$Form = M ("word"); Sort by ID to display the first 6 records import ("@.org.page"); Import a paging class $count = $Form->count (); Total count $p = new Page ($count, 1); $list = $Form->limit ($p->firstrow. ', '. $p->listrows)->order (' id desc ')->findall (); $page = $p->show (); $this->assign ("page", $page); $this->assign ("list", $list); $this->display (); Template call, this is the key. }//data is inserted into public function insert () {$word = D ("word"); if ($vo = $word->create ()) {if (False!== $word->add ()) {$this->success ("data added successfully"); } else {$this->error (' Data write Error! '); }} else {$this->error ($word->geterror ()); }}//Verify duplicate Public function Checktitle () {if (!empty ($_post[' username ')) {$Form = M ("word"); Getbytitle is the model of obtaining data based on a field to obtain records of the Magic Method//such as GetByID etc getbyxxx XXX Capital if ($Form->getbyusername ($_post[' username ')) {$this->error (' title already exists '); } else {$this->success (' title can be used! '); }} else {$this->error (' title required '); } }}
Here's the code to validate the model
Class Wordmodel extends model{ protected $_validate = Array ( array (' username ', ' require ', ' salutation must! ', 1),//1 for must verify array (' email ', ' email ', ' email ' format Error! ', 2),//2 is not NULL when validating array (' QQ ', ' number ', ' QQ ' error ', 2), Array (' content ', ' require ', ' contents must ', 1), Array (' Username ', ', ' salutation already exists ', 0, ' unique ', 1) ; Protected $_auto = Array ( ' datetime ', ' get_date ', 1, ' callback '), array (' IP ', ' GetIP ', 1, ' callback ') ); protected function Get_date () { return date ("y-m-d h:i:s"); } protected function GetIP () { return $_server[' REMOTE_ADDR '];} }
Thinkphp there is a need to note that in the curd operation, it is required to use the table name.
More about thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.