Rewriting URLs that have variables in |
[eluser]Craig Ward[/eluser]
Hi, I have just started using codeigniter and love it. I am rewriting my website with codeigniter and have something I want to do but not sure it is possible. I have a gallery on my site powered by the Flickr API. Here is an example of the code I use to display the Landscape pictures: Code: <?php foreach ($landscapes->photoset->photo as $l->photoset->photo) : ?> As you can see when a user clicks on a picture I pass over the Farm, Server, ID, Secret and Title elements using URI segments and build the page in the controller using Code: $data['farm'] = $this->uri->segment(3); Everything works and is fine but the URL's are a tad long, example "http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old Mill House in Donegal" Is there a way to rewrite the URL so its more like "http://localhost:8888/wip/index.php/gallery/focus/Old_Mill_House_in_Donegal" I was looking at using: Code: $url_title = $this->uri->segment(7); But I don't seem to be able to get it to work. Any ideas?
[eluser]danmontgomery[/eluser]
[quote author="Craig Ward" date="1269531915"]But I don't seem to be able to get it to work.[/quote] Can you be more specific?
[eluser]Craig Ward[/eluser]
The url is being rewitten. The Codeigniter userguide doesn't have many examples.
[eluser]danmontgomery[/eluser]
I'm still not sure I understand... If you build the link using: Code: $url_title = $this->uri->segment(7); You would end up with exactly what you're looking for: Quote:http://localhost:8888/wip/index.php/gall...in_donegal Assuming title is unique, you could then use that to get the information you need...
[eluser]Craig Ward[/eluser]
The current url is for example: “http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old Mill House in Donegal” Now rather than just putting in underscores so it is like: “http://localhost:8888/wip/index.php/gallery/focus/3/2682/4368875046/e8f97f61d9/Old_Mill_House_in_Donegal” I want to rewrite the URL so it looks like: “http://localhost:8888/wip/index.php/gallery/focus/Old_Mill_House_in_Donegal” I don't think I am implementing it correctly or even if that is what url_title() is suposed to do.
[eluser]danmontgomery[/eluser]
It is... url_title() just converts a string to an seo-friendly (and url friendly) string.
[eluser]Craig Ward[/eluser]
Yes but I also want to get rid of the /3/2682/4368875046/e8f97f61d9 uri segments
[eluser]danmontgomery[/eluser]
Code: foreach ($landscapes->photoset->photo as $photo) { in config/routes.php, Code: $route['gallery/focus/(:any)'] = 'gallery_controller/gallery_method/$1'; And the function to show the image: Code: function gallery_method($url_title) {
[eluser]Craig Ward[/eluser]
Cheers for that, I will give this whirl later tonight and let you know how I get one. Thanks for the help |
Welcome Guest, Not a member yet? Register Sign In |