原thinkphp6开启注解路由后,提示控制器类 Class /app/app/admin/controller/Index.php does not exist 解决方法
摘要:ThinkPHP支持使用注解方式定义路由,如何正确开启?
目录
1. 安装注解路由
composer require topthink/think-annotation
2. 在控制器中使用
<?phpnamespace app\controller;use think\annotation\Route;class Index{/*** @param string $name 数据名称* @return mixed* @Route("hello/:name")*/public function hello($name){return 'hello,'.$name;}}
3. 出现错误:Class does not exist 提示
#0 [-1]ReflectionException in InteractsWithRoute.php line 55Class /private/var/www/project/mishop/app/admin/controller/Index.php does not exist
4. 解决方法
4.1. 打开 InteractsWithRoute.php 文件
应用目录/vendor/topthink/think-annotation/src/InteractsWithRoute.php
4.2. 找到 54 行以下代码修改
//修改前protected function scanDir($dir){foreach (ClassMapGenerator::createMap($dir) as $class) {...//修改后protected function scanDir($dir){foreach (ClassMapGenerator::createMap($dir) as $class =>$path) {...
保存,刷新浏览器,则可以正常thinkphp6的注解功能了!
结论
目前注解还存在一些bug,谨慎使用!
手机扫码阅读,舒服~


