Welcome Guest, Not a member yet? Register   Sign In
Need a helping hand with CI Routes
#1

[eluser]systemsos[/eluser]
Howdy everyone,

Just after a little bit of help with CI's routes. I have the following setup.

I have a main controller, which handles dynamic menus and their content. So in my example I'm re-doing my website (it desperately needs my love and attention and not a 2 minute hack).

I have the following things redirect to the default controller - which determines what section we're looking at, and what page of that section we're looking at.

I have;
/domains
/domains/some-pages
/hosting
/hosting/some-pages
/another-thing
/another-thing/and-it's-pages

Now I've been using routes for ['domains'] and pushing it back to my default controller, but that requires me to edit the routes.php file itself any time a new section is added.

As far as CMS goes - I don't like that idea.

I could use no route - and create a proper handling controller so that my site was
mysite.com/site/domains - but I want to remove the /site/ all together.

So now I've added a [':any'] and [':any/:any'] clause in my routes config. Which pushes "everything" back to the default controller. But I want "blog" for example to not be pushed there.

So I add a ['blog'] = "blog"; to goto that controller instead. But then if I goto /blog/something it doesn't work.

If I add ['blog/:any'] = "blog" - it just pushes it back to the default controller (and the index function) rather than where I would want it to go (it's normal function).

This isn't a problem at the moment, but I just thought I would see if anyone else has done something similar to what I'm trying to do.

Cheers for your thoughts Smile

[i]Edit: I have been trying to do something like $route['blog/:any'] = "blog/$2" but I don't actually know the proper setup for this.
#2

[eluser]BravoAlpha[/eluser]
[quote author="systemsos" date="1204020702"]Edit: I have been trying to do something like $route['blog/:any'] = "blog/$2" but I don't actually know the proper setup for this.[/quote]
Code:
$route['blog/(:any)'] = "blog/$1"
#3

[eluser]systemsos[/eluser]
God you're good. Thank you so much. I knew it would be something so simple. Brackets and $1 it was!

Code:
$route['admin'] = "admin";
$route['admin/(:any)'] = "admin/$1";
$route['blog'] = "blog";
$route['blog/(:any)'] = "blog/$1";

$route[':any'] = "default_controller";
$route[':any/:any'] = "default_controller";

For me, there would only ever be a handful of "static" sections, so it's far easier to default everything, and add my "static" entries (admin/blog/forums) rather than the other way around.

Thank you again!




Theme © iAndrew 2016 - Forum software by © MyBB