Welcome Guest, Not a member yet? Register   Sign In
Routing - probably easy for you
#1

[eluser]Radon[/eluser]
Hi there

I've got a problem (yes I really suck at regular expressions).

I have a standard codeigniter page with the default controller "start".
My pages are loaded with ajax, and because I want the pages still to be able to be bookmarked I change the URL with javascript (local.hash).

The URLs do look like this, when changed with js (surely I can also change the things after the "#"):

http://domain.ch/#/content/contact

Well now I need a route which routes everything that comes on domain.ch/#/anything, to domain.ch/start/anything.

I thought it should look like this:

$route['#/:any'] = "start/$1";

It doesn't work - I guess it's just wrong.
Can anyone help me?

Thanks in advance.
#2

[eluser]bretticus[/eluser]
I really don't think you can do that and it's not a code igniter thing it's a browser standard. When you browser sees # I'm sure it calls just /. Again I don't think there's anyway around that.

Quote:RFC 2396 section 4.1:

When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, separated from the URI by a crosshatch ("#") character, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed. As such, it is not part of a URI, but is often used in conjunction with a URI.
#3

[eluser]BrianDHall[/eluser]
According to my testing now on my system, the hash (# - number sign or crosshatch, if you prefer) is not transmitted to the server. It is, as bretticus notes, purely used by the browser.

Nothing you could really do would allow CI itself to reroute it, because by HTTP standard and browser common practice the server (and thus CI) never knows about it.
#4

[eluser]Zack Kitzmiller[/eluser]
I can absolutely guarantee that the hash is never seen by the server.
#5

[eluser]Radon[/eluser]
Hmm ok - I also thought of that. but than...shouldnt it work by default? I mean by calling #/start/content/contact

but it doesn't :/
#6

[eluser]BrianDHall[/eluser]
[quote author="Radon" date="1254864655"]Hmm ok - I also thought of that. but than...shouldnt it work by default? I mean by calling #/start/content/contact

but it doesn't :/[/quote]

The expected behavior is if you call mysite.com/#/start/content/contact you should get the default index page as if you simply visited mysite.com - no matter what you have set in your routes file.

Is this not what you experience?
#7

[eluser]Radon[/eluser]
Nono this is exatctyl what I got - i think then I missunderstood you. I thought the "#" will simple be ignored and not everything AFTER the "#" ....

But if this doesnt work...then how is it possible, that facebook is able to do it?

For example facebook image urls are like this:

http://www.facebook.com/home.php#/photo....&id=111111
#8

[eluser]BrianDHall[/eluser]
[quote author="Radon" date="1254865686"]Nono this is exatctyl what I got - i think then I missunderstood you. I thought the "#" will simple be ignored and not everything AFTER the "#" ....

But if this doesnt work...then how is it possible, that facebook is able to do it?

For example facebook image urls are like this:

http://www.facebook.com/home.php#/photo....&id=111111[/quote]

The link I get is: http://www.facebook.com/photo.php?pid=123&id=123

When you click images from there you will notice the page does not refresh, but then #/photo.php?pid=123&id=123 appears after the above link.

Up to the hash mark is sent to the server, returning the page like with facebook. The rest is manipulated by javascript, as javascript can access the info after the hash mark because it resides on the server.

You will need to ditch the routing approach, and if you want it to work like facebook it's purely a client-side javascript functionality where their AJAX grabs the pid and id from the url after the hash mark and puts a request in to the server to get the new image.
#9

[eluser]Radon[/eluser]
Ok thank you I got it.

Well I don't have the intention in doing it exactly like facebook - I just WANNA be able to do it (My problem is that all my pages on my site are loaded with ajax, but I still want that the URL changes and I think the only way to do this is with the location.hash js function). But if that's the way, I'll give it a try.




Theme © iAndrew 2016 - Forum software by © MyBB