2
votes

Trying to learn Kohana, coming from Asp.Net MVC 3. In MVC I am used to the default route (very similar to the default route in Kohana) working like this:

The default route matches any of these:

/
/Home
/Home/Index

I expected it to be the same in Kohana, but it seems all it matches is this:

/

Here's my setup in bootstrap.php:

Kohana::init(array(
    'base_url'   => '/kohana',
                 'index_file' => FALSE
));

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

So if I enter localhost/kohana in the address bar I get to the view called by controller home and action index (action_index). But if I enter localhost/kohana/home/index I get an error saying the object doesn't exist.

Why is this? Shouldn't I be able to enter controller and action in the url and get the correct routing? So basically I have no idea how to enter URLs to get to an action method...

Sorry if this is a stupid newbie question, but I can't figure it out Googling and looking at the Kohana docs... I've been sort of spoiled by the fact that Asp.Net MVC routing always just worked, so I never had to really learn about it...

1
By default your route should be matched, so it's hard to say what's wrong. Do you have any other routing rules? - matino
No, I haven't defined any other routes apart from changing the default controller to home instead of welcome, as you see in the example. No other routes added... Like I said, localhost/kohana works, but not localhost/kohana/home/index - Anders
Have you modified .htaccess with RewriteBase /kohana/? - matino
No, I tried that now, but I've never used .htaccess. But mine was called example.htaccess, don't know if that matters? It didn't help anyway... Is my base_url wrong? (see above) My application structure is c:\xampp\htdocs\kohana\ , and under there obviously the application folder etc... - Anders
Check my answer then, it should solve the problem - matino

1 Answers

2
votes

Rename example.htaccess to .htaccess, open it and change the line RewriteBase / to RewriteBase /kohana/. Windows explorer will probably not allow for a file without the name, so you have to use another file manager (Total Commander for example).