CodeIgniter Forums
Trouble showing subcategories - 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: Trouble showing subcategories (/showthread.php?tid=11093)



Trouble showing subcategories - El Forum - 08-25-2008

[eluser]cyberbuff[/eluser]
hello. I am new to ci and somewhat new to php ( with about 3 months exp). I have a controller: category. I want to show subcategories like somesite.com/category/subcat... how can i do that? I already have a index() function for category controller...what should be the next function?
the category controller looks like this:
Code:
if( !defined('BASEPATH') ) exit("No direct access, please!");
class Categories extends Controller
    {
    function Categories()
        {
        parent::Controller();
        //load stuff
        $this->load->model("categories_model");
        }
    function index()
        {
        $data["categories"] = $this->categories_model->showAllCategories();
        $this->load->view("header");
        $this->load->view("all_categories", $data);
        $this->load->view("footer");
        }
Regards
Abhisek


Trouble showing subcategories - El Forum - 08-25-2008

[eluser]Colin Williams[/eluser]
I think you are failing to look beyond the most basic convention of uri routing. See the Controllers section of the User Guide for some more clues, specifically the _remap() method.

Also, we have no idea what you intend to display or achieve with your category/subcat pages, so it's hard to make any specific recommendations.


Trouble showing subcategories - El Forum - 08-26-2008

[eluser]lukeinjax[/eluser]
You could also do something like this...

Code:
function index() {
        if ($this->uri->segment(3)):
            $data["categories"] = $this->categories_model->functionToGetSubCat($this->uri->segment(3));            
        else:
            $data["categories"] = $this->categories_model->showAllCategories();            
        endif;

        $this->load->view("header");
        $this->load->view("all_categories", $data);
        $this->load->view("footer");
}



Trouble showing subcategories - El Forum - 08-26-2008

[eluser]cyberbuff[/eluser]
thanks lukeinjax. that perfectly does the job. Thanks so much! Smile