ThinkPHP writes the first module application

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.