ThinkPHP写第一个模块应用_PHP教程

WBOY
Freigeben: 2016-07-21 15:20:04
Original
863 Leute haben es durchsucht

找到项目文件夹下面的Lib/Action这个目录,在下面有个创建好的例子IndexAction.class.php,加入我们创建的是admin这个项目,那么./admin/Lib/Action/IndexAction.class.php,这个模块是默认加载的模块。在ThinkPHP中,自动加载的动作、方法、操作等等都是以index命名的。
下面,我们创建一个自己的模块,比如UserAction,class.php(注意命名规则),我们编辑这个文件:

复制代码 代码如下:

//先继承Action这个类,注意:文件名要与类名保持一致
class UserAction extends Action
{
//每个模块中默认加载的动作(操作、方法)是index方法
function index ()
{
echo '你来到了user模块';
}
//方法(操作、动作)命名规则是:第一个单词小写紧跟着的首字母大写
function listName()
{
echo '你的名字是'.$_GET['name'];
}
}
?>

接下来在浏览器测试:
输入:http://thinkphp.com/admin.php?m=user,输出:你来到了user模块
输入:http://thinkphp.com/admin.php?m=user&a=index,输出:你来到了user模块
输入:http://thinkphp.com/admin.php?m=user&a=listname,输出:你的名字是
输入:http://thinkphp.com/admin.php?m=user&a=listname&name=123,输出:你的名字是123

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325155.htmlTechArticle找到项目文件夹下面的Lib/Action这个目录,在下面有个创建好的例子IndexAction.class.php,加入我们创建的是admin这个项目,那么./admin/Lib/Action/...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!