• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble showing subcategories

#1
[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

#2
[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.

#3
[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");
}

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.