Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize controllers in a directory?

I just started using Laravel. When I use codeigniter or zend framework, I can organize my controller into a separate directory. For example, I can create 'user/permission.php' and 'user/group.php'.

How do I do that with Laravel?

like image 828
Moon Avatar asked Oct 08 '12 05:10

Moon


2 Answers

Convert / into _. So your controllers/user/permission.php controller would be

class User_Permission_Controller

UPDATE:

You also have to route to the controller changing _ to . So route similar to

Route::get('/', 'user.permission@index');

You can see more details on it here. http://codehappy.daylerees.com/using-controllers

like image 101
Robbo Avatar answered Oct 14 '22 10:10

Robbo


(This is basically the same answer as Robbo gave with some extra examples).

I use the following (tested) structure. I have a file controllers/admin.php which looks like:

class Admin_Controller extends Base_Controller {
    ...
}

And I have files like controller/admin/groups.php which look like:

class Admin_Groups_Controller extends Admin_Controller {
    ...
}

And in the routes.php file I have

// Route to all controllers
Route::controller(Controller::detect());
like image 39
Hendrik Jan Avatar answered Oct 14 '22 11:10

Hendrik Jan