^Status|Draft|
^Todo| GET support|
====== Kohana URLs ======
URLs in Kohana are composed of segments. A typical segmented URL is http://localhost/control/action/arg1/arg2
The segments correspond (in order ) to a controller, a controller method, and the method arguments.
**Example**
http://localhost/index.php/articles/edit/1/my-first-article
// or the same URL with url rewriting on
http://localhost/articles/edit/1/my-first-article
When you segmentize this url it becomes
* **articles** (the controller)
* **edit** (the action)
* **1** (first argument)
* **my-first-article** (second argument)
This will correspond to the controller **articles** found for example in ''application/controllers/articles.php'' - see [[general::controllers|Controllers for more information]]
The second segment maps to a method **edit** in the Articles_Controller class in ''application/controllers/articles.php'' If no second segment is set it will call the **index()** method. If a non-existing method is set it will try to call **%%__call%%()** or trigger a 404.
Note: You cannot pass arguments to an index method, unless the URI contains index in the second segment.
The third and fourth segment refer to arguments given to the **edit()** method. E.g. edit(**$id**,**$title**)
An example of what a controller could look like when this url is used.
**Example**
class Articles_Controller extends Controller {
function __construct(){
parent::__construct();
}
function index()
{
}
function edit($id,$title){
//get the article from the database and edit it
echo $id;
$view = new View('articles/edit');
}
}
===== Segments =====
As said, Kohana urls contain segments.
**Example**
http://localhost/articles/edit/1/my-first-article
Contains the segments
* articles
* edit
* 1
* my-first-article
A [[libraries:uri|URI]] class and a [[helpers:url|URL]] helper provide methods to make working with a url easier. You can retrieve segments, determine the current url segment, and various other operations.
===== URL rewriting =====
By default, Kohana urls contain ''index.php''. This does not look very nice and also is not optimized for search engines. See the difference between the following urls.
http://localhost/index.php/articles/edit/1/my-first-article
// or the same URL with url rewriting on
http://localhost/articles/edit/1/my-first-article
The latter looks nicer and is SEO proof.
There is an [[http://kohanaphp.com/tutorials/remove_index|example .htaccess]] included with Kohana, which should be part of your installation files.
===== Suffix =====
Kohana allows you to set a suffix to your urls.
**Example**
http://localhost/index.php?/articles/edit/1/my-first-article.html
Setting this can be done in the ''application/config/config.php'' file under **url_suffix**
===== Query strings and GET support =====
Query strings and GET support are enabled in Kohana. You can simply append your urls with ?var=value to pass it on. The keys and values are inspected and cleansed by the Input library when global_xss is on.