Consider this route in bootstrap.php
...
Route::set('crud', 'staff/<controller>(/<action>(/<id>))', array(
'controller' => '(activities|users|default-emails)',
'action' => '(new|view|modify|delete)',
'id' => '\d+'
))->defaults(array(
'directory' => 'staff',
'action' => 'view'
));
The default-emails
is trying to run the action_default-emails()
method which obviously doesn't and can't exist.
What part of Kohana should I extend to map that hyphen into a underscore internally?
Should I be concerned that if I do do this, then it will be accessible via both _
and -
delimited routes?
Thanks.
The simplest is to hack
Kohana_Request::execute()@1112
change to
But you understand, that you have to do this patch in each next kohana version.
More harmless could be to extend
Kohana_Route::matches()
Did not check, but I bet it should work.
Since Kohana 3.3 came out this method no longer works. I have found a solution that, so far, works for me.
When upgrading to 3.3, you don't need to edit the Internal.php request file. Instead, you can create a Route Filter. All you need to do is replace hyphen in the action to an underscore.
This obviously only works for the methods. However, if you explore a little further, you can create a better function for the directory, controller, etc.
My solution for Kohana 3.2 for routing hyphenated actions to the appropriate underscored method:
Extend Kohana_Route and insert this code
Full Solution: Create a file route.php in application/classes/
An update to zerkms's method. In Kohana 3.2, you need to edit the file
system/classes/kohana/request/client/internal.php
line 106.Replace:
By:
I dislike hacking frameworks but this is by far the simplest and most reliable solution. Renaming the action in the Route class can lead to all sorts of troubles, because the action will then sometime be called my_action (internally) and sometime my-action (in links).