James Thompson
James Thompson

Reputation: 1027

Kohana 3.2 Routes: Multiple Directories

I have a route:

Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>');

I would like to route this url to the following controller/action:

/application/classes/<directory>/subdir/<controller>.php::action_<action>()

I already have and need this route too, which complicates things:

Route::set('foo', '<controller>/<variable>/<action>');

Is that possible?

Upvotes: 2

Views: 1203

Answers (3)

Tomek
Tomek

Reputation: 49

Use REGEXP to catch directory and subdirectory as /directory/subdirectory/controller/action to match Route like // where regexp allows you to put / inside directory. Then make little modification in your Route class to change all / to the _

It is not tested ... yet. ;) But im about to...

Upvotes: 0

shadowhand
shadowhand

Reputation: 3201

I would like to append the subdir to the directory

This will be possible in Kohana v3.3 using the new Route::filter functionality. There is currently no way to do this in Kohana 3.1 or 3.2 without modifying the Route and/or Request classes.

Upvotes: 0

Kemo
Kemo

Reputation: 7042

Why not, as long as the default route is defined after the directory route.

Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>')
    ->defaults(array(
        'directory'     => 'default_directory',
        'controller'    => 'index',
        'variable'      => 'default_variable',
        'action'        => 'index',
    ));

Kohanas routing supports directories 'natively', there is no need to hack anything.

Please note your class names will have to include the directory name as well.

Upvotes: 3

Related Questions