How would I build a hook in Kohana to send URLs to absent methods back to index()?
Question
How would I construct a hook in Kohana so that ...
http://www.example.com/a_controller/non_existing_method
would route to to the controller title 'a_controller' except call the controller's index method and pass 'non_exisitng_method' as an argument?
It should also allow a fallback, so that if non_existing_method IS a method, it should route to that method.
So, my hook would, in the absence of a matching method, route to the index and provide the rest of the URL as arguments to the index.
How would I do this?
Solution
Implement the __call
method in your controller. This is the one called when a non exisitng method in your controller is called. By default it does a 404 but you can specify what you want.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow