David
David

Reputation: 3310

Kohana RegEx routing and case sensitivity

I want to build case insensitive route with Kohana 3.2

example (as from Kohanas site):

Route::set('sections', '<directory>(/<controller>(/<action>(/<id>)))',
array(
    'directory' => '(admin|affiliate)'
))
->defaults(array(
    'controller' => 'home',
    'action'     => 'index',
));

will work with: example.com/admin/home/index but not with: example.com/Admin/home/index (capital 'A').

how can I solve this problem? And I don't want to write something like: 'directory' => '([Aa]dmin|[Aa]ffiliate)' it's "wrong".

Upvotes: 1

Views: 728

Answers (2)

diggersworld
diggersworld

Reputation: 13080

Here's a nicer example of the overload method:

<?php

/* APPPATH/classes/route.php */

class Route extends Kohana_Route {

    public static function compile ( $uri, array $regex = NULL ) {
        if ( ! is_string( $uri ) ) { return; }
        return parent::compile( $uri, $regex ) . 'i';
    }

}

Source: https://gist.github.com/2045349

Upvotes: 2

Darsstar
Darsstar

Reputation: 1895

You could overload Route::compile and return parent::compile($uri, $regex).'i'; or pass a strtolower(Request::detect_uri()) to Request::factory() in index.php if you want all routes to be case insensitive.

Or if you only want that route to be case insensitive you could make it a lambda/callback route in which you use strtolower().

Upvotes: 2

Related Questions