Codeigniter加载不同的站点内容,可以选择可能的过滤器

时间:2014-03-21 07:21:08

标签: codeigniter url redirect views

我有2个输入字段。在第一个过滤器用户可以选择类别,子类别,在第二个过滤器用户可以选择产品。 提交表单后,用户将根据他在输入字段中的选择重定向到站点。

    $category = $this->input->post('category', true);
    $product = $this->input->post('product', true);

    if(isset($category) && $sub_category == ''){
        redirect(base_url().'/category/'.$category);
    }elseif(isset($category) && isset($product)){
        redirect(base_url().'/category/'.$category.'/product/'.$product);
    }else{
        $this->session->set_flashdata('error', 'You must select a category');
        redirect($_SERVER['HTTP_REFERER']);
    }

根据用户的输入选择创建网址并重定向到这些网址可以正常工作。我无法理解的是如何为每个网站获取不同的视图内容。类别和产品的每种可能组合都有自己的内容。如何为每个可能的URL加载单个内容? 谢谢你的提示!

1 个答案:

答案 0 :(得分:0)

试试这个以获取网址

$category = $this->input->post('category', true);
$product = $this->input->post('product', true);
$url =array();
if($category){
    $url[] = 'category/'.$category;
}
if($product){
    $url[] ='product/'.$product;
}
$newurl = implode('/',$url);
redirect($newurl);