Shameem
Shameem

Reputation: 14339

Passing extra paramaters via route configuration in Kohana

Is there a mechanism to pass extra parameters to Controller actions in Kohana?

Eg:

$config['article/([0-9]+)'] = array('path' => 'news/show/$1', 
                                    'params' => array(
                                       'param1' => 'some_stuff',
                                    ));

The Kohana routing documentation doesn't seem to discuss this. But, is there a way to get this working.

Upvotes: 1

Views: 1781

Answers (5)

jfountain
jfountain

Reputation: 3815

This has changed in Kohana 3 you have to change your bootstrap.php file to make this work.

from the unofficial wiki

http://kerkness.ca/wiki/doku.php?id=routing:routing_basics

Basic Route with 2 parameters

Unlike KO2, KO3 Routing default in your bootstrap does not handle 2 or more parameters like example.com/<controller>/<action>/<param1>/<param2>

In you bootsrtap.php file...

  Route::set('default', '(<controller>(/<action>(/<id1>(/<id2>))))')

Upvotes: 1

antpaw
antpaw

Reputation: 15985

it happens automatically, you don't need to do anything in the routing config, just do this

class Controller_News extends Controller {
     public function action_show($param1, $param2 = "can have default value too"){
          // can be called with 'yoursite.com/news/show/param1/param2'
     }
}

Upvotes: 1

Christian Dav&#233;n
Christian Dav&#233;n

Reputation: 18107

Routes rewrite URLs, so you can include any data you want in the new URL, but not in the way you suggest. The key is to understand that you can only enter a URL.

This is one way to do it:

$config['article/([0-9]+)'] = 'news/show/$1/some_stuff';

Then you can catch the arguments in the News controller's show method.

See also the Kohana documentation on Controller with arguments.

If you need something fancier, you can create more complex URLs or serialize and urlencode data in the URL.

Upvotes: 0

Lukman
Lukman

Reputation: 19119

Or maybe if you want the extra parameters to be $_GETable variables, then:

$config['article/([0-9]+)'] = 'news/show/$1?param1=some_stuff&param2=another_stuff';

Upvotes: 0

Sarfraz
Sarfraz

Reputation: 382646

I think you can go this way to whatever level you like:

$config['article/([0-9]+)'] = 'news/show/more/more/more/etc/$1';

Upvotes: 0

Related Questions