Welcome Guest, Not a member yet? Register   Sign In
Building a search with unique URLs?
#1

[eluser]Tomed[/eluser]
I'm currently redesigning a poorly implemented web portal that consists of hundreds of HTML pages with endless amounts of copy/pasting. The portal collects links from various sites and 'tags' them much like WordPress does with blog articles.

My current task: I want to implement a search by tag feature on the site that will return unique links (again, like WordPress). If I search by a tag, for example, 'Tutorials' then I'd like a unique link like www.mysite.com/search/Tutorials. Similarly I will find out how to implement a tag cloud and would like to be able to click on, for example, 'Tutorials' and it would again link to www.mysite.com/search/Tutorials.

I was first going to accomplish this with the GET method but I've seen other sites do it with the clean URLs. My portal has hundreds of tags and I'd like it to be as dynamic as possible so I don't want to create a function for each tag in some controller. How do people usually implement stuff like this?

edit: I should mention that my database is fully populated and I've already implemented a search by tag feature but I just haven't figured out how to generate the unique URLs without creating new controller methods for each tag.
#2

[eluser]mddd[/eluser]
If you have a controller called search, you can put in a method called _remap.
That method will ALWAYS be called, whatever is behind 'search' in the url.
The first part of the url after the controller name is passed to the _remap method, so that it's easy for you to acccess.

Code:
function _remap($method)
{
  // if search/tutorials is called, $method is 'tutorials'.
  // use $method to look up stuff in your database.
}

Check the "routes" page of the CI manual for more information.
#3

[eluser]Tomed[/eluser]
Amazing! This is EXACTLY what I was looking for.

Thanks!
#4

[eluser]mddd[/eluser]
You're welcome. It's a feature not everybody knows about, but it's so essential to building dynamic sites!




Theme © iAndrew 2016 - Forum software by © MyBB