在codeigniter中维护网页,类别,子类别和产品的网址?

时间:2017-05-04 10:16:10

标签: codeigniter

我正在尝试使用以下网址格式

页面 -

www.example.com/page-name 对于类别

www.example.com/category-name/sub-category-name 对于产品

www.example.com/category-name/sub-category-name/product-name

1 个答案:

答案 0 :(得分:0)

如果您只使用一个控制器,即默认控制器,这应该不是问题。假设您的默认控制器被称为" Home"。然后你就可以做到这一点。

class Home extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Home_model');
     }
    public function _remap()
    {
        $category = $this->uri->segment(2);
        $sub_category = $this->uri->segment(3);
        $product = $this->uri->segment(4);
// Check what you have 
 // echo $category.'_'. $sub_category.'_'. $product; 

        if($category == '' || $sub_category == '' || $product == '')
      {
        //send user to landing page of website
         $this->load->view('landing');
      }
      else
      {
        // get the product details
        $render['product_details] = $this->Home_model->get_product_details($category, $sub_category, $product);
         // send product details to view
        $this->load->view('product_details', $render);
      }
    }
}