


Method to implement message board based on thinkPHP framework_php example
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('标题必须'); } } }
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']; } }
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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 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 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

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

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 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 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 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
