Home > Backend Development > PHP Tutorial > thinkpade400578mdc ThinkPHP writes the first module application

thinkpade400578mdc ThinkPHP writes the first module application

WBOY
Release: 2016-07-29 08:48:06
Original
1193 people have browsed it

Find the Lib/Action directory under the project folder. There is a created example IndexAction.class.php below. The admin project we created is ./admin/Lib/Action/IndexAction.class.php. This module is the module loaded by default. In ThinkPHP, automatically loaded actions, methods, operations, etc. are named after index.
Next, we create our own module, such as UserAction, class.php (note the naming rules), we edit this file:

Copy the code The code is as follows:


//Inherit first Action class, note: the file name must be consistent with the class name
class UserAction extends Action
{
//The default action (operation, method) loaded in each module is the index method
function index ()
{
echo ' You have come to the user module';
}
//The naming rules for methods (operations, actions) are: the first word is lowercase, followed by the first letter in uppercase
function listName()
{
echo 'Your name is'. $_GET['name'];
}
}
?>


Next, test in the browser:
Input: http://thinkphp.com/admin.php?m=user, output: You are here user module
Input: http://thinkphp.com/admin.php?m=user&a=index, output: You have come to the user module
Input: http://thinkphp.com/admin.php?m=user&a=listname , Output: Your name is
Input: http://thinkphp.com/admin.php?m=user&a=listname&name=123, Output: Your name is 123

The above introduces the first module application written by thinkpade400578mdc in ThinkPHP, including the content of thinkpade400578mdc. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template