Welcome Guest, Not a member yet? Register   Sign In
Passing variables via URI segments to controller index()
#18

[eluser]naren_nag[/eluser]
[quote author="jedd" date="1237146466"]You do realise that the CI framework does this already, yeah?

It takes the first segment, and sends you to that controller. It takes the second segment, and sends you to that method within the controller. I'm not sure what you're trying to gain by subverting this approach in this particular instance.

I refer you again to my original [url="http://ellislab.com/forums/viewreply/547558/"]question above[/url] on how you resolve segment/method name clashes.[/quote]


To answer your question: You make all the methods private.

Here's how I'm using it. I've got a controller called Tag. Now when I call mysite/tag/codeigniter I want to find everything tagged with codeigniter. But when I call mysite/tag/scripts/codeigniter I only want to find scripts tagged with codeigniter. If I just call mysite/tag/scripts I get redirected to the main scripts display page.

Here's my remap function:

Code:
function _remap() {
    
    $this->tag_or_entry_type = $this->uri->segment(2);
    $this->tag = $this->uri->segment(3);
    
    $this->index();
}

And in my index function I run a simple switch case on $this->tag_or_entry_type, where I check if the user is trying to find articles etc, but as my default I'm calling a private search function that returns articles, scripts and downloads tagged with the tag passed.

This is a bookmark friendly way of setting up intuitive URLs for users, especially where search is involved.


cheers,


Messages In This Thread
Passing variables via URI segments to controller index() - by El Forum - 06-04-2009, 08:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB