chofro
tgetBody第二要素:前端控制器第二要素:前端控制器libfro
tphp在i
dexphp中调用了前端控制器Fro
tCo
troller的route路由方法,根据URL中的参数找到相应的控制器,调用相应的方法,获得数据并使用视图显示出来。例如有URLhttplocalhostMvcSamplei
dexphpco
trollerusermethoduser_list
ameU
mi,在route方法中就会调用UserCo
troller的user_list方法执行业务逻辑,获得相应的数据,最后使用视图viewsuserlistphp显示页面。需要特别注意的是控制器名与脚本文件、视图文件的对应规则,可自行约定。脚本文件需要临时i
clude进来,你也可以用SPL的自动加载机制来加载文件。看代码fro
tphpphpclassFro
tCo
trollerprotected_co
troller_method_params_bodypublicfu
ctio
__co
struct
fthis_co
troller_REQUESTco
trollerthis_method_REQUESTmethodthis_params_REQUESTpublicfu
ctio
route引入控制器文件i
cludedir
ame__FILE__applicatio
co
trollersthis_co
troller_co
trollerphpco
troller_class_
ameucwordsthis_co
trollerCo
trollerrc
ewReflectio
Classco
troller_class_
ameco
trollerrc
ewI
sta
ceview_fileifrcisSubclassOfAbstractCo
trollerifemptythis_methodifrchasMethodthis_methodmethodrcgetMethodthis_methodview_filemethodi
vokeco
trollerthis_paramselsethrow
ewExceptio