ThinkPHP框架下自定义控制器步骤

WBOY
Release: 2016-06-13 12:13:31
Original
1448 people have browsed it

ThinkPHP框架下自定义控制器方法
每个模块是一个Action文件,因此应用开发中的一个重要过程就是给不同的模块定义具体的操作。一个应用如果不需要和数据库交互的时候可以不需要定义模型类,但是必须定义Action控制器,一般位于项目的Lib/Action目录下面。
Action控制器的定义非常简单,只要继承Action基础类就可以了,例如:

  1. Class UserAction extends Action{}
控制器文件的名称是UserAction.class.php。
如果我们要执行下面的URL
http://localhost/App/index.php/User/add
则需要增加一个add操作方法就可以了,例如 
控制器文件的名称是UserAction.class.php。
如果我们要执行下面的URL
http://localhost/App/index.php/User/add

则需要增加一个add操作方法就可以了,例如

<?php //用户模块    class UserAction extends Action{        //定义一个add操作方法         public function add(){            //add操作方法逻辑的实现            // ...            $this->display();//输出页面模板        }    }
Copy after login


操作方法必须定义为Public类型,否则会报错。并注意操作方法的命名不要和内置的Action类的方法重复。系统会自动定位当前操作的模板文件,而默认的模板文件应该位于项目目录下面的
Tpl\User\add.html
Related labels:
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!