0
votes

I'm having a route for user controller. This controller has about 20 methods so I don't want to set them manually in routes:

Route::set('user', 'user/<action>')
        ->defaults(array(
            'controller' => 'user',
            'action'     => 'index',
        ));

I have also pictures controller (Controller_User_Pictures) with multiple methods that is used to manage users pictures. When I create a route:

Route::set('pictures', 'user/pictures/<action>')
        ->defaults(array(
            'directory'  => 'user',
            'controller' => 'user_pictures',
            'action'     => 'index',
        ));

It's not working.

Even if I create a separate controller (Controller_Pictures) and create route it's not working:

Route::set('pictures', 'user/pictures/<action>')
        ->defaults(array(
            'directory'  => 'user',
            'controller' => 'pictures',
            'action'     => 'index',
        ));

In all cases it returns error: Method action_pictures does not exist which means that router is looking for an action called pictures in user controller which of course is wrong.

The only solution that I'm thinking of, is to define all routes in bootstrap.php file. Do you have better solution?

Edit Second question, do have any idea how to replace underscore with hyphen in any actions (of course in routing)?

1

1 Answers

1
votes

The order of the routes is important; specific routes should come first.

So your url user/pictures/<action> is triggering the first route. If you put the pictures-route above the general user-route, it should work just fine.

Another side-note: if you specify directory 'user', your controller would be Controller_User_Pictures in classes/controller/user/pictures.php