A method of message board implementation based on thinkphp framework

Source: Internet
Author: User
This article mainly introduces the method of message board based on thinkphp framework, analyzes the process of the thinkphp frame and the related core code of controller and model, and needs the friend to refer to the following

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 (' <font color=red> title already exists </font> ');      } 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.

Related Article

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.