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

thinkphp控制器调度使用示例

时间:2018-09-17 09:26:33

相关推荐

thinkphp控制器调度使用示例

后端开发|php教程

thinkphp,控制器

后端开发-php教程

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

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

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

ReflectionClass主要用的方法:

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

getMethod(string) 获取方法

ReflectionMethod 主要方法:

getNumberOfParameters() 获取参数个数

getParamters() 获取参数信息

3.代码演示

php 多级分销系统源码,vscode 作者,ubuntu启用休眠,tomcat小猫,sqlite表上限,cmd 进入阿里云ip服务器,电子原件插件 人工,若依前端框架,nodejs爬虫乱码,正规php培训中心,seo技术栈,ck小说网站,网页开发软件,ecshop 京东模板,dede 注册页面修改,公安娱乐管理系统,行业门户网站程序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’,’test’);

$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!’;

棋牌app源码出售,vscode跑代码哪个键,ubuntu data分区,tomcat设置超时退出,aspx页面爬虫,iis8 php 配置,广东品质seo优化哪家好,起点中文网站源码,html文件管理系统模板lzw

/PHPjc/825264.true/PHPjc/825264.htmlTechArticle1.如何通过地址栏参数来得到模块名称和控制器名称(即使在有路由和开了重写模块的情况下) 2.tp是如何实现前置,后置方法功能模块,和如…

易语言钓鱼生成器源码,ubuntu 上方菜单消失,tomcat 压缩包配置,网页验证爬虫,php怎么查找数据,搜索引擎seo优化有什么用lzw

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