Welcome Guest, Not a member yet? Register   Sign In
routes question
#1

[eluser]Emrys[/eluser]
Hey all

So I have an interesting question. Well interesting to me anyway Smile.

I built my entire site with codeigniter originally. I've now moved to wordpress for the main page, since I don't have enough time to manage the back end, but it's also left me with a bit of a tricky problem as far as the routes go.

My main controller used to be (cleverly) called 'main' and I also had a 'gallery' controller. So my url for the gallery used to look something like this :

http://main/index.php/gallery/albums

Now that main has been removed, I thought I'd cleverly switch my front controller to the gallery. So my base url would be :

http://localhost/gallery

The problem is, is that now my albums function now lives here :

http://localhost/gallery/index.php/gallery/albums

Which is not exactly what I want Smile. Does anyone have any ideas on how to do this in a way that actually works? I basically need to make my gallery the front controller without having to rewrite the entire thing. I have this nagging feeling that it should be fairly straightforward but I just can't see it.

Thanks in advance
Marc
#2

[eluser]Emrys[/eluser]
hmm.. could I phrase this better, or has no-one encountered this before?

Thanks
Marc
#3

[eluser]Dam1an[/eluser]
I think you're confusing yourself (and definatly confusing me)
You talk of main and gallery being controllers and yet in the URL examples, you have index.php after main and gallery respectivly, which would suggest that they're the folder you installed CI in, and in both cases, the controller is gallary (the part after index.php)
#4

[eluser]Emrys[/eluser]
ah..haha...

yeah definitely confused.

ok here was the original url :
http://example.com/index.php/gallery/albums
http://example.com/index.php/main/
etc.

The second one remains valid though. So now CI is installed to :
http://example.com/gallery/
but my primary controller is gallery too, so if I remove the index.php the it would be something like :
http://example.com/gallery/gallery/

um, hopefully that's better. Smile

Thanks
M
#5

[eluser]Dam1an[/eluser]
Ah, that clears things up

So all you (should) need is
Code:
$route['default_controller'] = "gallery";
// So now http://example.com/gallery/ points to http://example.com/gallery/gallery (the gallery controller)

$route['albums'] = "gallery/albums";
// So now http://example.com/gallery/albums points to http://example.com/gallery/gallery/albums (the albums function in the gallery controller)
#6

[eluser]Emrys[/eluser]
ah... that helped clarify things. Thanks I got it working now.

Oddly enough I'd actually worked all this out a year ago when I first coded it, it's amazing how things fall away when you don't use them.

Thanks again.
Marc
#7

[eluser]Emrys[/eluser]
Hey

Sorry to resurrect an old problem. But while this solution works it has the potential to get pretty messy. Currently my routes look like this:
$route[':num'] = "gallery/index";
$route['search'] = "gallery/search";
$route['albums:any'] = "gallery/albums";

I was wondering if there wouldn't perhaps be a more elegant solution than basically replicating almost every function (ok not every function Wink) in my routes file?

Thanks
Marc




Theme © iAndrew 2016 - Forum software by © MyBB