欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

lumen框架Controllers文件夹下注册路由异常

程序员文章站 2022-03-10 13:54:25
...
1.lumen Controllers结构
    Controllers
         --Test
             --TestController.php
         

2.注册路由

$app->get("test",'Test\TestController@est');

3.lumen报错;

    lumen.ERROR: ReflectionException: Class App\Http\Controllers\Test\TestController does not exist in /Users/shumingjian/Desktop/www/lumen/vendor/illuminate/container/Container.php:734      
    

4.Testcontroller代码:

    

namespace AppHttpControllersTest;

use AppHttpControllersController as Controller;

class TestController extends Controller
{

public function test(){
        echo 1132;
}

}
?>

该代码在Controllers下可以正常输出,但在ControllersTest文件夹下异常

lumen 版本 5.2.9

回复内容:

1.lumen Controllers结构

    Controllers
         --Test
             --TestController.php
         

2.注册路由

$app->get("test",'Test\TestController@est');

3.lumen报错;

    lumen.ERROR: ReflectionException: Class App\Http\Controllers\Test\TestController does not exist in /Users/shumingjian/Desktop/www/lumen/vendor/illuminate/container/Container.php:734      
    

4.Testcontroller代码:

    

namespace AppHttpControllersTest;

use AppHttpControllersController as Controller;

class TestController extends Controller
{

public function test(){
        echo 1132;
}

}
?>

该代码在Controllers下可以正常输出,但在ControllersTest文件夹下异常

lumen 版本 5.2.9

看起来是找不到 AppHttpControllersTestTestController 这个类,路由定义是没错的,应该是类加载的问题。

你试着运行 php artisan tinker,然后在 shell 里运行 $foo = new App\Http\Controllers\Test\TestController; 看看能不能找到这个类。

相关标签: lumen php