Question

I want make such URL: http://somecontroller.example.com where somecontroller will be any controller... I am using Kohana3.1.

I know routing as well as make many routes but I haven't one such as that...

I have those default routes in bootstrap:

Route::set('default', '(<controller>(/<action>(/page<page>)(/<id>)))')
    ->defaults(array(
                'directory'  => 'index',
        'controller' => 'main',
        'action'     => 'index',
    ));

No correct solution

OTHER TIPS

Kohana's routing system only allows you to parse the URI, so you can't do it in a clean way. But, you can do something like this to have your desired behaviour:

$controller = preg_match('/^([\w]+)\.example\.com$/', $_SERVER['HTTP_HOST'], $match)
? $match[1]
: 'main';

Route::set('default', '(<action>(/page<page>)(/<id>))')
    ->defaults(array(
        'directory'  => 'index',
        'controller' => $controller,
        'action'     => 'index',
    ));

However, this routing won't work in console (php index.php --uri=<uri>), because HTTP_HOST isn't defined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top