0

I wonder what is the most appropriate way to do in this scenario:

Assume there is a link (method) called browse. When user clicks on that link the page shows a list of cities. When user click on some city the page shows available categories for that city. When some category is clicked the page shows sub categories for selected category.

When user click on some link of sub categories the page is reloaded and show a result based on selected city, category and sub category.

For example the URI will look like

foo.bar/browse/city/rubrics/subrubric/

Which is the right way to do with CodeIgniter?

1 Answer 1

3

CI works with URI segments.

For the above to work (without routing) your method could look something like:

function browse($city=null,$category=null,$subcat=null)
{
    if($category==null && $subcat==null)
    {
        $this->load->view('show_cities'):
    }

    if($city!=null && $category!=null && $subcat==null)
    {
        $this->load->view('show_categories');
    }

    if($city!=null && $category!=null && $subcat!=null)
    {
        $this->load->view('show_subcats');
    }

}

the load->view is just an example, you'd have some interaction with the model or whatever.

Now if you browse to site.com/browse/city/foo/bar you'll see the subcats - CI passes the URI segments to the method.

There are of course other ways to do this, this is just one - and probably isn't the most efficient.

Sign up to request clarification or add additional context in comments.

1 Comment

You can also make a Method for showing cities, another for categories and another for sub-categories so call different methods for each one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.