author:咔咔
wechat:fangkangfk
文件我就放到資源裏邊了,須要的去下載https://download.csdn.net/download/fangkang7/10759068javascript
建立test模塊php
並寫index控制器html
源碼:前端
<?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); } }
前端代碼:java
<!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>
頁面非常不漂亮,將就用,後邊有時間了在寫樣式jquery
咱們就測試上一篇文章的模型關聯預加載json
文件我就放到資源裏邊了,須要的去下載https://download.csdn.net/download/fangkang7/10759068app