标题 | thinkphp3.x自定义Action、Model及View的简单实现方法 |
内容 | 本文实例讲述了thinkphp3.x自定义Action、Model及View的实现方法。分享给大家供大家参考,具体如下: 1、在xmall/Lib/Action中创建文件TestAction.class.php class TestAction extends Action{ function index(){ $this->display("test"); } } 2、在xmall/tpl下创建default文件夹,在default下创建Test文件夹,在Test下创建test.html模版文件; 3、执行URL:http://localhost/xmall/index.php/Test/index就会出现test.html页面的内容 4、在操作过程中出现的错误: (1) URL中的Test的T要大写; (2) Display不需要提供文件的扩展名,默认为index 5、注意事项: (1) 为方便调试,应在index.php入口文件中添加 define("APP_DEBUG",true); (2) 最好在配置文件(xmall/Conf/config.php)中指定默认模版:'DEFAULT_THEME' => 'default' 6、在xmall/lib/Model下创建文件UserModel.class.php class UserModel extends Model{ function test(){ return "123456"; } } 7、在xmall/Lib/Action/TestAction.class.php添加新方法 public function test(){ $m=D("User"); echo $m->test(); } 8、执行URL:http://localhost/xmall/index.php/Index/test,页面输出123456 9、注:Model文件名要与model的名称一直,并且在调用时区分大小写; 在xmall/conf/config.php中添加'URL_CASE_INSENSITIVE' =>true,//URL不区分大小写 希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。 |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。