文件我就放到资源里边了,需要的去下载https://download.csdn.net/download/fangkang7/10759068
创建test模块
并写index控制器
源码:
<?php namespace app\test\controller; use think\Controller; use Request; class Index extends Controller { public function index(Request $request) { return view(); } public function execute(Request $request) { $arr = $request::param();// 注意这里 $namespace = $arr['namespace']; $className = $arr['className']; $action = $arr['action']; $param = $arr['param']; // 判断 命名空间写全了 类命名空间完善 $class = ($className == "") ? $namespace : $namespace.'\\'.$className; // 要提换的值 需要的结果 $class = str_replace("/", "\\", $class); // 创建需要测试的类 $service = new $class(); // 参数的解析 $param = ($param == "") ? [] : explode('|', $param) ; // 执行测试类方法 $data = call_user_func_array([$service, $action], $param); // 输出 return (is_array($data)) ? json_encode($data) : var_dump($data); } }
前端代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script type="text/javascript" src="__ADMIN__static/js/jquery.js"></script> <title>Document</title> </head> <body> <h1>不区分大小写</h1> <br> 命名空间:<input type="text" value='' style="width:300px" id='namespace' placeholder="如:app\index\controller 或app\index\controller\Index">可以写全,然后下面类名不用些<br> 类名:<input type="text" id='className' placeholder="如:index ">命名空间全可以不用写<br> 测试方法名:<input type="text" id='action' placeholder="index"><br> 传递参数以 | 分割:<input type="text" placeholder="如: 1|2|3" id='param'><br> <br> <input type="button" name="" value="测试" onclick="test()"> </body> <script type="text/javascript"> console.log(`{:URL('test/index/execute')}`); function test() { var namespace = $("#namespace").val(); var className = $("#className").val(); var action = $("#action").val(); var param = $("#param").val(); window.location.href = `{:url('test/index/execute')}?namespace=${namespace}&className=${className}&action=${action}¶m=${param}`; } </script> </html>
文件我就放到资源里边了,需要的去下载https://download.csdn.net/download/fangkang7/10759068