Welcome Guest, Not a member yet? Register   Sign In
Using helpers in Routes.php ??
#1

[eluser]umbungo[/eluser]
I would like to know how i can use a helper in routes.php.

I have a list of main categories in config.php, and a custom url helper. I would like to do the following instead of mainting 2 separate lists;
Code:
foreach(config_item('categories') as $category){
    $categ = url_encode($category);
    $route[$categ] = "main/main/$categ";
    $route[$categ.'/:any'] = "main/main/$categ/$1";
}
However this stops everything from working. I tried loading the helper manually also (it is in autoload), but this didn't help.
#2

[eluser]CroNiX[/eluser]
Nope, not natively. You probably could if you extended the router class. Routes get loaded way early on in the bootstrap process as it's needed to determine which controller/method to load and process. Check the /system/core/CodeIgniter.php file to see how most things get loaded and in what order.
#3

[eluser]umbungo[/eluser]
Could i just copy the code from the helper into routes.php? could i use it as a function then?/how
#4

[eluser]Aken[/eluser]
You could add the function to your index.php, config file or route file and have it work fine. It would then make it globally available just like autoloading a helper file.




Theme © iAndrew 2016 - Forum software by © MyBB