1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > thinkphp控制器调度使用示例【PHP】

thinkphp控制器调度使用示例【PHP】

时间:2018-06-30 12:46:38

相关推荐

thinkphp控制器调度使用示例【PHP】

后端开发|php教程

thinkphp控制器,调度

后端开发-php教程

1.如何通过地址栏参数来得到模块名称和控制器名称(即使在有路由和开了重写模块的情况下)

2.tp是如何实现前置,后置方法功能模块,和如何执行带参数的方法?

php系统自带的 ReflectionClass,ReflectionMethod 类,可以反射用户自定义类的中属性,方法的权限和参数等信息,通过这些信息可以准确的控制方法的执行

ReflectionClass主要用的方法:

hasMethod(string) 是否存在某个方法

getMethod(string) 获取方法

ReflectionMethod 主要方法:

getNumberOfParameters() 获取参数个数

getParamters() 获取参数信息

3.代码演示

android相册源码,vscode用c语言写窗口程序,ubuntu 超时时间,tomcat怎么启动jar文件,sqlite查询死锁,大学生dw网页设计作业,iis7 服务器拒绝了您的浏览请求.,discuz商品展示插件,主流web前端框架,爬虫怕盐吗,php5教程,衡水seo优化公司,一周学好springboot,音乐上传网站源码,ajax网页连接数据库,米拓模板下载,网站后台更新后主页没有变化,页面按钮图片素材,文库管理系统,多多返利程序破解版lzw

<?php

class IndexAction{

public function index(){

echo index."\r\n";

}

public function test($year=,$month=2,$day=21){

echo $year.--------.$month.-----------.$day."\r\n";

}

public function _before_index(){

echo __FUNCTION__."\r\n";

}

public function _after_index(){

echo __FUNCTION__."\r\n";

}

}

//执行index方法

$method = new ReflectionMethod(IndexAction,index);

//进行权限判断

if($method->isPublic()){

$class = new ReflectionClass(IndexAction);

//执行前置方法

if($class->hasMethod(\_before_index)){

$beforeMethod = $class->getMethod(\_before_index);

if($beforeMethod->isPublic()){

$beforeMethod->invoke(new IndexAction);

}

}

$method->invoke(new IndexAction);

//执行后置方法

if($class->hasMethod(\_after_index)){

$beforeMethod = $class->getMethod(\_after_index);

if($beforeMethod->isPublic()){

$beforeMethod->invoke(new IndexAction);

}

}

}

//执行带参数的方法

$method = new ReflectionMethod(IndexAction, est);

$params = $method->getParameters();

foreach($params as $param ){

$paramName = $param->getName();

if(isset($_REQUEST[$paramName]))

$args[] = $_REQUEST[$paramName];

elseif($param->isDefaultValueAvailable())

$args[] = $param->getDefaultValue();

}

if(count($args)==$method->getNumberOfParameters())

$method->invokeArgs(new IndexAction,$args);

else

echo parameters is not match!;

江湖商圈o2o系统 源码,vscode调用qt,ubuntu使用gpt,阿帕奇 和tomcat,java sqlite储存,jquery手势插件,腾讯有没有前端框架,爬虫实战题目,php=>,seo淘宝优化,端午节专题网站代码,音乐播放器网页代码,amaze ui 手机模板,html商品页面代码,crm客户管理系统免费版源码,在线播放音乐整站程序下载lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。