Reputation: 8980
Using Kohana 3.3, I created a tabbed interface and I'm trying to detect which tab is active based on a route parameter.
Testing with 2 urls which look like this: mysite.com/p/mycontroll
and: mysite.com/p/Francis-Lewis/mycontroll
My route looks like this:
Route::set('profile', 'p(/<name>)(/<controller>(/<action>))', array(
'name' => '[\w\-]+',
'controller' => '[a-z]+',
'action' => '(view|edit|save|delete|create|cancel)',
))->defaults(array(
'name' => null,
'directory' => 'profile',
'controller' => 'main',
'action' => 'index',
));
The route itself is working fine, selecting the mycontroll
controller.
Here's where the problem comes in.
In the controller:
$this->request->param('controller'); // returns NULL
In the view
<?= Request::current()->param('controller') ?> // returns NULL
After banging my head around for a while, I added a function to the Kohana Request class to return the $_params
array to see what was in there.
Here's all it returns:
name => 'Francis Lewis'
Any ideas how to get the current controller?
Upvotes: 0
Views: 958
Reputation: 130
If you are absolutely sure that you want the initial controller then you can use the next method:
Request::initial()->controller();
otherwise use this method:
Request::current()->controller();
Upvotes: 0
Reputation: 506
There is a function for that in in the request object:
$this->request->controller(); // Returns the current controller as a String
Upvotes: 1