Previously, we created the first ThinkPHP project. Next we will create the first module application.
Previously, we created the first ThinkPHP project. Next we will create the first module application.
Find the Lib/Action directory under the project folder, and the created example IndexAction is as follows. class. php, join the admin project we created, so. /admin/Lib/Action/IndexAction. class. php. This module is loaded by default. In ThinkPHP, The automatically loaded actions, methods, and operations are all named after indexes.
Next, we will create a module of our own, such as UserAction and class. php (note the naming Rules). We will edit this file:
The Code is as follows:
// Inherit the Action class first. Note: The file name must be consistent with the class name.
Class UserAction extends Action
{
// The default action (operation and method) loaded in each module is the index method.
Function index ()
{
Echo 'you have come to the user Module ';
}
// The naming rule for methods (operations and actions) is: the first letter followed by the first letter in lowercase
Function listName ()
{
Echo 'your name is '. $ _ GET ['name'];
}
}
?>
Next, test in the browser:
Input: http://thinkphp.com/admin.php? M = user. Output: You are in the user module.
Input: http://thinkphp.com/admin.php? M = user & a = index. Output: You are in 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.