【发布时间】:2021-10-07 07:55:18
【问题描述】:
在我的 codeigniter 网站中,我创建了一个产品页面并使用 url 中的类别名称在其中显示产品:
<?php foreach($category as $cat): ?>
<li><a href="<?php echo base_url()?>homecontroller/products/<?php echo $cat->name;?>"><?php echo $cat->name;?></a></li>
<?php endforeach; ?>
public function products()
{
$id = $this->uri->segment(3);
$material = $this->input->post('material1');
$material2 = $this->input->post('material2');
$data['products'] = $this->product->findAll($id,$material,$material2);
$this->load->view('products', $data);
}
我的模特:
function findAll($id,$material,$material2)
{
$this->db->where('cname', $id);
if(!empty($material) || !empty($material2)) {
$this->db->or_where('material', $material);
$this->db->or_where('material', $material2);
}
return $this->db->get('product')->result();
}
和我的过滤器产品视图:
<form action="<?php echo base_url()?>products" method="post">
<input type="checkbox" name="material1" value="cotton" class="form-check-input filled-in" id="new" onChange="this.form.submit()">
<input type="checkbox" name="material2" value="polyster" class="form-check-input filled-in" id="used" onChange="this.form.submit()">
</form>
这里的问题是,当用户选择过滤器选项时,页面会重新加载并且过滤器是否正常,但 url 变成了我的基本 url/products,这使得产品页面显示所有没有类别的产品,谁能告诉我如何解决这个问题,提前谢谢
【问题讨论】:
-
缺少最重要的部分,即材质过滤器的表单。
标签: php codeigniter codeigniter-3