By "key = parameter" I assume you mean something like http://twitter.com?user=maronems
right? This is ugly, we can do better.
Let's look at making your URLs look like http://twitter.com/maronems
instead.
You'll want to look at Kohana's routing system.
Take a look at this route:
Route::set('username route', '<username>')
->defaults(array(
'controller' => 'Profile',
'action' => 'index',
));
Firstly, it's called
username route
, this is an aribitrary name, but a good one because it's intent is clear.Next look at the regex pattern
<username>
. This route is going to capture the username and store it in a variable calledusername
.Now notice that the route doesn't have to specify the controller and action. The routing system will get those from the default values. In this example you'll need a controller called
Controller_Profile
with an action calledaction_index
.
So let's look at the controller now:
<?php
class Controller_Profile extends Controller {
function action_index()
{
echo 'Hello ' . $this->request->param('username');
}
}
Of course you shouldn't user echo like this in classes, but to illustrate the point, if you visit example.com/maronems
you should see Hello maronems
echoed out.