Home  >  Article  >  Backend Development  >  如何实现thinkphp框架那种在浏览器地址栏里输入类中方法名即可访问

如何实现thinkphp框架那种在浏览器地址栏里输入类中方法名即可访问

PHP中文网
PHP中文网Original
2016-06-20 12:41:111368browse

如果用原生php的话每一个html页面都要对应一个php文件,感觉好麻烦。  
thinkphp框架却可以将所有的视图操作写成各个方法放在一个控制器类里面,再在地址栏里直接调用控制器类的方法。  
我想知道这是怎么弄的?






回复讨论(解决方案)

通过URL路由判断需要调用的类及方法,调用之。原理就这么简单。

我又看了一下,tp框架是通过一个index.php文件来判断url,从而跳转到不同的方法的吗?

根据 m 访问那个模块,根据 c 和 a 用反射(ReflectionMethod),调用方法  
在 \ThinkPHP\Library\Think\App.class.php 中可查到

 以上就是如何实现thinkphp框架那种在浏览器地址栏里输入类中方法名即可访问的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
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