_php example of the method of realizing message board based on thinkphp framework

Source: Internet
Author: User
Tags php template smarty template

This paper illustrates the method of implementing the message board based on thinkphp framework. Share to everyone for your reference, specific as follows:

Struggled for a day, finally thinkphp Little Deng message version of the concept version out

In fact, the real thinkphp development speed, as an internet "moving bricks", engaged in such a pure code farming is understandable.

The code implements the following functions

1. Message function.

2. Verification function.

3. Paging display function.

is to write a few lines of code (PS: Page design Code does not count, even if the controller and model Code)

The following I publish the control of the code, about thinkphp code rules I do not elaborate, look at the thinkphp manual can be.

Class Indexaction extends Action {public Function index () {$Form = M ("word");    Displays the first 6 records import ("@.org.page") by ID sort;  Import a paging class $count = $Form->count ();
      Total number of calculations $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 insertion public Function insert () {$word = D ("word"); if ($vo = $word->create ()) {if (False!== $word->add ()) {$this->success ("data added as
         Work "); 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 for obtaining data from a field to obtain a record of the Magic method//For example GetByID etc getbyxxx xxx Capital if ($Form->getbyusername ($_post[' username ')) {$this->error (' <font C
      Olor=red> title already exists </font> ');
      else {$this->success (' title can use! ');
    } else {$this->error (' title must ');

 }
  }
}

The following is the code for the validation model

Class Wordmodel extends model{
  protected $_validate = Array (
   ' username ', ' require ', ' salutation must!) ', 1,//1 for must verify
   array (' email ', ' email ', ' mailbox format error!) ', 2,//2 is not null-time verification
   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 stipulated to use the table name.

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.