Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write ThinkPHP data pagination

Shulou Source: shulou.com Published: 2022-06-03 09:07:52 09月17日 Update

This article mainly introduces "how to write ThinkPHP data pagination". In daily operation, I believe many people have doubts about how to write ThinkPHP data paging. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to write ThinkPHP data paging". Next, please follow the editor to study!

1. First, we have to create a database test.sql code for paging testing as follows.

CREATE TABLE `test` (`id` int (10) unsigned NOT NULL auto_increment, `name` char (100) NOT NULL, `content` varchar (300) NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=27 INSERT INTO `test` (`id`, `name`, `content`) VALUES (19, '123,' 123), (20, '1231,' 123123), (21, '123123,' 123123123'), (26,'24, '123123), (25,' 321123, '321123'), (24, 'age',' age'), (23, '123123,' 123123'), (22, '213),' 123123')

two。 Next, we have to create a new ThinkPHP project. The new version of tp has built-in the ability to automatically generate the project directory.

Create a new test folder under htdocs (that is, your website root), place the THINKPHP core folder in the test root directory, and create a new file index.php in the test root directory. Add the following code:

/ / define the ThinkPHP framework path define ('THINK_PATH','. / Thinkphp'); / / define the project name and path. These two sentences are the main points. Define ('APP_NAME',' test'); define ('APP_PATH','. / test'); / load framework entry file require (THINK_PATH. "/ ThinkPHP.php"); / / instantiate a website application instance $App = new App (); / / Application initialization $App- > run ()

Run "http://localhost/test/index.php"." You will see the welcome page of ThinkPHP. Then open your test directory and find that there is an extra test folder in the root directory. At this time, your project directory has been generated.

Open the / test/test/conf/ directory, create a new "config.php" and configure your database connection.

If you want to turn on debug mode, add it to the array

"debug_mode" = > true

3. The realization of basic page input and output.

(1) Open / test/test/lib/action/IndexAction.class.php and you will find the following code

Tags: Data files databases code templates forms actions instances folders root directories directories pages projects learning generation input functions parameters websites automatic generation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS MySQL Shulou Technology Redmi