codeigniter method question
I`m writing my first codeigniter (news) website. 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 catego开发者_运维百科ry 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 ?
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.
精彩评论