-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Controller class name vs file name #36
Comments
I think L4 way is much more cleaner, and allows you to organize your app in a cleaner way, yes in L3 you could do 'auth@login', but you memorize that the first parameter is the Controller, in the L4 version you don't need to memorize anything, you just need to read and identify where is the controller and where is method. |
Much prefer L4's way of specifying controllers to respond a route. There is no convention anymore (which I'm stoked about) for naming of, well, any class in L4. This leads to huge flexibility. If you require your app to have this logic, you could create a package and put it up on composer or you could simply edit a couple of files to manipulate the core to behave like you'd want. You could also do something like: <?php
// in start.php
$app['router'] = $app->share(function($app) { return new MyCustomRouter($app) });
// in MyCustomRouter.php
class MyCustomRouter extends Illuminate\Routing\Router {
protected function createControllerCallback($attribute)
{
list($controllerAlias, $method) = explode('@', $attribute);
$actualController = ucfirst($controllerAlias).'Controller';
return parent::createControllerCallback($actualController.'@'.$method);
}
} And vòila, you've got your app-specific controller assumptions and logic. |
I think I forgot to dump-autoload after renaming. Foo.PHP and classname Foo works fine. |
In L4 you can actually name things any way you like as it isn't mapped that way, it uses composers autoloader which will map a file path to whatever class is used. So you could name your file |
Install tactician
Minor fixes
L4 it seems that your controller class cannot be called something like 'Auth.php' - must be 'AuthController.php' Class name must match file name, unlike L3 you could have 'Auth.php' class name 'Auth_Controller'.
This means when generating a URL, 'AuthController@login' must be used as opposed to 'auth@login' which was legal in L3.
The text was updated successfully, but these errors were encountered: