ThinkPHPthinkphp 5获取所有控制器的名称和方法方法 /** *获取某个目录下的php文件名的函数 */ function getControllers($dir) { $pathList = glob($dir . '/*.php'); $res = []; foreach($pathList as $key => $value) { $res[] = basename($value, '.php');作者王明昌发布时间2018-09-26最后更新2018-09-27 方法 复制/** *获取某个目录下的php文件名的函数 */ function getControllers($dir) { $pathList = glob($dir . '/*.php'); $res = []; foreach($pathList as $key => $value) { $res[] = basename($value, '.php'); } return $res; } /** *获取某个控制器的方法名的函数 *此方法过滤父级Base控制器的方法,只保留自己的 */ function getActions($className, $base='\app\admin\controller\Admin') { $methods = get_class_methods(new $className());//当前控制器方法 $baseMethods = get_class_methods(new $base());//通用方法 $res = array_diff($methods, $baseMethods); return $res; } 代码 复制public function ceshi() { //获取所有控制器 $controllers = getControllers('../application/admin/controller'); //结果: // array (size=13) // 0 => string 'Admin' (length=5) // 1 => string 'Article' (length=7) // 2 => string 'Config' (length=6) // 3 => string 'Goods' (length=5) // 4 => string 'Index' (length=5) // 5 => string 'Login' (length=5) // 6 => string 'Menu' (length=4) // 7 => string 'Mysql' (length=5) // 8 => string 'Order' (length=5) // 9 => string 'Other' (length=5) // 10 => string 'Upload' (length=6) // 11 => string 'User' (length=4) // 12 => string 'Wechat' (length=6) //下面是获取Index控制中你定义的方法,在mobadmin的应用场景中$control由前端传入,这样就能够达到我选择某个一个控制器的时候,就会输出这个控制中定义的方法。 $control = 'Index'; $actions = getActions('app\admin\controller' . '\\' . $control); //结果: // array (size=3) // 0 => string 'index' (length=5) // 1 => string 'welcome' (length=7) // 2 => string 'ceshi' (length=5) //系统中所有控制的方法怎么获取呢?遍历所有控制器就可以。 $controllers = getControllers('../application/admin/controller'); $actionsAll = []; foreach( $controllers as $key=>$value) { $actions[$value] = get_class_methods('app\admin\controller' . '\\' . $value); } //结果: // 'Admin' => // array (size=15) // 0 => string '__construct' (length=11) // 1 => string '_initialize' (length=11) // 2 => string '_empty' (length=6) // 3 => string 'beforeAction' (length=12) // 4 => string 'fetch' (length=5) // 5 => string 'display' (length=7) // 6 => string 'assign' (length=6) // 7 => string 'engine' (length=6) // 8 => string 'validateFailException' (length=21) // 9 => string 'validate' (length=8) // 10 => string 'success' (length=7) // 11 => string 'error' (length=5) // 12 => string 'result' (length=6) // 13 => string 'redirect' (length=8) // 14 => string 'getResponseType' (length=15) // 'Article' => // array (size=18) // 0 => string 'index' (length=5) // 1 => string 'category' (length=8) // 2 => string 'comment' (length=7) // 3 => string '__construct' (length=11) // 4 => string '_initialize' (length=11) // 5 => string '_empty' (length=6) // 6 => string 'beforeAction' (length=12) // 7 => string 'fetch' (length=5) // 8 => string 'display' (length=7) // 9 => string 'assign' (length=6) // 10 => string 'engine' (length=6) // 11 => string 'validateFailException' (length=21) // 12 => string 'validate' (length=8) // 13 => string 'success' (length=7) // 14 => string 'error' (length=5) // 15 => string 'result' (length=6) // 16 => string 'redirect' (length=8) // 17 => string 'getResponseType' (length=15) }
2018-02-27tp5controller与model使用数据库控制器里使用数据库 use think\Db; $info = Db::table('fly_user')->select();//用些前缀,全部查询 $info = Db::table('fly_u
2018-04-30TP5错误 | A non well formed numeric value encountered数据表字段是create_time timestamp 默认:CURRENT_TIMESTAMP 使用时间会出现以下错误: A non well formed numeric value encoun
2018-02-02tp3.2-if三层嵌套问题if标签 value1 value2 value3 if标签不支持三层嵌套,所以第三层不要用if标签,用eq标签;就能解决三层嵌套。 相等不相等 还有更多比较标签可以使用 http://documen
2018-07-04转载 | ThinkPHP5+Layui实现图片上传加预览 图片 上传图片 layui.use('upload',function(){ var upload = layui.upload, jq = layui.jquery; upload.render