Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lumen 5.1 | Namespace inheritance in nested route group #461

Closed
zxz054321 opened this issue Aug 12, 2016 · 4 comments
Closed

Lumen 5.1 | Namespace inheritance in nested route group #461

zxz054321 opened this issue Aug 12, 2016 · 4 comments

Comments

@zxz054321
Copy link

zxz054321 commented Aug 12, 2016

According to the doc
(These paragraphs have been removed in the document of Lumen 5.2)

Controllers & Namespaces

It is very important to note that we did not need to specify the full controller namespace when defining the controller route. We only defined the portion of the class name that comes after the App\Http\Controllers namespace "root". By default, the bootstrap/app.php file will load the routes.php file within a route group containing the root controller namespace.

If you choose to nest or organize your controllers using PHP namespaces deeper into the App\Http\Controllers directory, simply use the specific class name relative to the App\Http\Controllers root namespace. So, if your full controller class is App\Http\Controllers\Photos\AdminController, you would register a route like so:

$app->get('foo', 'Photos\AdminController@method');

Everything is ok

$app->get('hi', 'FooController@bar');
$app->get('foo/bar', 'FooController@bar');

These routes should be OK, too

$app->group(['prefix' => 'foo'], function ($app) {
    $app->get('bar', 'FooController@bar');
});

But actually that will throw a ReflectionException. Lumen can't find my controller class.

After adding 'namespace' => 'App\Http\Controllers', the route group works.

$app->group(['prefix' => 'foo', 'namespace' => 'App\Http\Controllers'], function ($app) {
    $app->get('bar', 'FooController@bar');
});
@GrahamCampbell
Copy link
Member

Ping @taylorotwell RE docs.

@lalxyy
Copy link

lalxyy commented Aug 22, 2016

Yeah this actually happens. My Lumen version in composer.json is 5.2.8. Alternatively I'm using duplicated prefixes in my route definitions.

@lalxyy
Copy link

lalxyy commented Aug 24, 2016

@zxz054321
See issue #239 ...?
We're talking about the same issue.

@GrahamCampbell
Copy link
Member

Moving over to the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants