laurent
laurent

Reputation: 90863

How to have URLs with dashes in Kohana 3.x

I need to have a URL such as http://example.com/controller/my-page-with-dashes

How can I have such as URL in Kohana? I tried creating a controller and name the action myPageWithDashes like in the Zend Framework but that didn't work. Any idea how it should be done?

Upvotes: 1

Views: 620

Answers (3)

RJD22
RJD22

Reputation: 10350

Just as zombor said change the regex of the route:

Route:

Route::set('default', 'controller/<url>)', array('url' => '[-a-z0-9]+'))
    ->defaults(array(
        'controller' => 'page',
        'action' => 'index',
  ));

Controller:

Class Controller_Page {

    public function action_index()
    {
        $url = $this->request->param('url');
    }
}

array('url' => '[-a-z0-9]+') This part changes what is allowed in the url param.

Upvotes: 1

zombor
zombor

Reputation: 3257

No, you just need to specify a regex parameter in your route.

Read the docs on routes, it explains this: http://kohanaframework.org/3.2/guide/kohana/routing#regex

Upvotes: 1

laurent
laurent

Reputation: 90863

Copy the file system/classes/kohana/request/client/internal.php to your application folder - application/classes/kohana/request/client/internal.php. Then change line 106 from:

$action = $request->action();

to:

$action = str_replace('-', '_', $request->action());

Upvotes: -1

Related Questions