I want the following behaviour:
-
http://www.example.com/ Should go to: http://example.com/welcome
( DONE BY setting default_controller in routes.php)
- http://www.example.com/controllerName/functionName Should go to
controllerName, and then its function IF THE CONTROLLER EXISTS . - If the
controllerNamedoes not exist, it should go to :
specialController and specialFunction withfunctionaNameas
parameter
eg. http://www.example.com/greatProducts should become
http://www.example.com/specialController/specialFunction/greatProducts if greatProducts controller does not exist, (it can be any string, not just greatProduct, the case being the same i.e. the controller with that name does not exist)
Would want to preferably implement this using routing rules,
changing URI segments by editing libraries does not seem a good option to me.
THIS WORKS:
I tried it out by editing Routes.php in core/Routes.php and adding something like
`$segments = array("specialController","specialFunction",$segments[0]);
return $segments;`
if it was found that the controller does not exist.
Try this (untested yet but should work):
Controller:
UPDATE:
that’s more tricky. A route like
would work, but it will catch ANY controller, so if you have other ones in your app, you need to whitelist them to avoid being catched by this. Ex: