ThinkPHP writes the first module application_PHP tutorial
Jul 21, 2016 pm 03:20 PM
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:
<?php
//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

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The role and practical application of arrow symbols in PHP

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code

How to Undo Delete from Home Screen in iPhone

There are several versions of thinkphp

Which one is better, laravel or thinkphp?
