ThinkPHP writes the first module application_PHP tutorial

WBOY
Release: 2016-07-21 15:20:04
Original
864 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 a module of our own, such as UserAction, class.php (note the naming rules), we edit this file:

Copy code Code 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, method) loaded in each module is the index method
function index ()
{
echo 'You have come to the user module';
}
// The method (operation, action) naming rules are: the first word is lowercase followed by the first letter in capital
function listName()
{
echo 'Your name is'.$_GET['name' ];
}
}
?>

Next test in the browser:
Enter: http://thinkphp.com/admin.php?m =user, output: you have come to the 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325155.htmlTechArticleFind the Lib/Action directory under the project folder. There is a created example IndexAction.class below. php, join the admin project we created, then ./admin/Lib/Action/...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!