CodeIgniter Forums
Sorting by categories - best practice - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Sorting by categories - best practice (/showthread.php?tid=47388)



Sorting by categories - best practice - El Forum - 12-06-2011

[eluser]Unknown[/eluser]
I am building a site which has 13 different categories. When a user clicks one of the categories I'm going to display the records that belong to that category. What's the best way to do this with Codeigniter?

I am retreiving the categories from the database and putting them into a list:

Code:
<ul>
        <li>Categories</li>
        &lt;?php foreach($categories as $category) : ?&gt;
        <li><a href="&lt;?php echo $category-&gt;name; ?&gt;">&lt;?php echo $category->name; ?&gt;</a></li>
  &lt;?php endforeach; ?&gt;
</ul>

When a user clicks on one of these categories how should I process that information?

My first thought is to create a new controller for categories and have a separate function for each category. Is that the best way? Or should I use $this->uri->segment?

Thank you.