Home Backend Development PHP Tutorial Method to implement message board based on thinkPHP framework_php example

Method to implement message board based on thinkPHP framework_php example

Dec 05, 2016 pm 01:28 PM
thinkphp framework message board

The example in this article describes how to implement a message board based on the thinkPHP framework. Share it with everyone for your reference, the details are as follows:

After struggling for a day, the concept version of THINKPHP Xiao Deng’s message board is finally out

In fact, the development speed of THINKPHP is very fast. As a "brick mover" on the Internet, it is understandable to engage in this kind of pure code farmer's work.

The code implements the following functions

1. Message function.

2. Verification function.

3. Paging display function.

Just wrote a few lines of code (PS: The page design code does not count, even the controller and model code)

I will publish the code of the controller below. I will not elaborate on the code rules of THINKPHP. Just read the thinkphp manual.

class IndexAction extends Action
{
  public function index() {
    $Form = M("word");
    // 按照id排序显示前6条记录
    import("@.ORG.Page");    //导入分页类
      $count = $Form->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(); //模板调用,这个是关键。
  }
  //数据插入
  public function insert() {
    $word = D("word");
     if($vo = $word->create())
       {
         if(false !== $word->add())
        {
           $this->success("数据添加成功");
         }
         else
         {
          $this->error('数据写入错误!');
         }
       }
    else
      {
       $this->error($word->getError());
      }
  }
  //验证重复
  public function checkTitle()
  {
    if (!empty($_POST['username'])) {
      $Form = M("word");
      //getByTitle是model的获取数据根据某字段获取记录的魔术方法
      //比如getById etc getByXXX XXX大写
      if ($Form->getByUsername($_POST['username'])) {
        $this->error('<font color=red>标题已经存在</font>');
      } else {
        $this->success('标题可以使用!');
      }
    } else {
      $this->error('标题必须');
    }
  }
}

Copy after login

The following is the code to verify the model

class wordModel extends Model{
  protected $_validate = array(
   array('username', 'require', '称呼必须!', 1),//1为必须验证
   array('email', 'email', '邮箱格式错误!', 2),//2为不为空时验证
   array('qq','number','QQ号错误',2),
   array('content', 'require', '内容必须',1),
   array('username','','称呼已经存在',0,'unique',1)
  );
  protected $_auto = array(
   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'];
  }
}

Copy after login

Thinkphp has one thing to note. In CURD operations, table names are required.

Readers who are interested in more thinkPHP related content can check out the special topics of this site: "ThinkPHP Getting Started Tutorial", "ThinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "Smarty Template Basic Tutorial" and "PHP Template Technology" Summarize".

I hope that what is described in this article will be helpful to everyone’s PHP program design based on the ThinkPHP framework.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does php use the ThinkPHP6 framework? How does php use the ThinkPHP6 framework? May 31, 2023 pm 03:01 PM

As web development continues to evolve, developers need to use some practical tools and frameworks to save time and effort while improving the quality of their applications. ThinkPHP is a popular PHP framework that greatly simplifies development and increases efficiency. In this article, we will learn how to use the latest version of ThinkPHP6 framework. Environmental requirements First, you need to confirm that your system meets the following requirements: PHP version 7.1 and above MySQL version 5.5 and above Composer is a

ThinkPHP Framework Guide in PHP ThinkPHP Framework Guide in PHP May 21, 2023 am 08:51 AM

ThinkPHP is a well-known PHP open source framework. It is characterized by efficiency, simplicity, and ease of use, and can quickly build large-scale Web applications. This article will introduce you to the usage and precautions of the ThinkPHP framework. 1. Installation of ThinkPHP framework 1. Download the ThinkPHP framework. You can download the ThinkPHP compressed package on the official website (http://www.thinkphp.cn/) and unzip it. You can also install it through Composer

How to implement a simple message board version 2.0 using PHP How to implement a simple message board version 2.0 using PHP Sep 24, 2023 pm 02:37 PM

How to use PHP to implement a simple message board version 2.0. With the rapid development of the Internet, message boards have become an important part of many websites. Message boards not only provide a platform for users to interact with the website, but also help website administrators understand users' real-time feedback and opinions. In this article, we will introduce how to use PHP to implement a simple message board version 2.0, including the functions of publishing, displaying and deleting messages. 1. Preparation Before starting, make sure you have installed PHP and a MySQL database server

PHP implements message board function PHP implements message board function Jun 22, 2023 pm 05:18 PM

With the popularity of the Internet, website message boards have become a must-have feature for many websites. There are many ways to implement message boards, one of the more common ones is to use PHP. This article will introduce how to use PHP to implement message board functions. 1. Front-end page design Before implementing the message board, we need to design the front-end page first. A typical message board page usually contains the following parts: 1. Message input box: used to enter message content. 2. Message list: used to display existing messages. 3. Message submission button: Use

How to use PHP to implement message board function How to use PHP to implement message board function Jun 27, 2023 pm 01:43 PM

With the development of the Internet, message boards, as a common way of communication, are widely used in various websites. In website development, how to use PHP to implement a simple message board function can help the website increase user interaction and improve the website experience. The following will introduce how to use PHP to implement the message board function. 1. Establish a database Before using PHP to implement a message board, you need to create a database first. You can use related tools, such as phpMyAdmin, etc., to create a message_board

How to use PHP to develop guest message board function How to use PHP to develop guest message board function Aug 26, 2023 pm 05:36 PM

How to use PHP to develop guest message board function Introduction: Guest message board is one of the common functions in website development. It allows users to leave comments or messages on the web page. In this article, we will use PHP language to develop a simple guest message board function that allows users to leave messages on the web page and display all messages. Below are specific steps and code examples. Step 1: Create database and data table First, we need to create a database to store the message information in the message board. Open phpMyAdmin (or other MySQ

Development suggestions: How to use the ThinkPHP framework for RBAC permission management Development suggestions: How to use the ThinkPHP framework for RBAC permission management Nov 22, 2023 pm 08:02 PM

"Development Suggestions for Using the ThinkPHP Framework for RBAC Permission Management" With the development of the Internet, more and more Web applications need to implement permission management functions to ensure the security and controllability of the system. RBAC (Role-BasedAccessControl, role-based access control), as a mature permission management model, has been widely used in actual development. ThinkPHP is a popular PHP framework that provides rich functions and flexible extensions.

How to develop a simple message board and comment function using PHP How to develop a simple message board and comment function using PHP Sep 20, 2023 pm 03:45 PM

How to use PHP to develop simple message boards and comment functions Introduction: Message boards and comment functions are one of the common requirements in website development. They allow users to express their opinions, exchange ideas, and increase the interactivity of the website. This article will introduce how to use PHP to develop a simple message board and comment function, and provide specific code examples for readers' reference. 1. Project preparation: Before starting development, we need to ensure that we have the following basic conditions: a server with Apache, MySQL and PHP installed; a blank H

See all articles