我需要在 codeigniter 中获取其类别的子类别。我被困在将类别 ID 传递给我的模型方法
我的代码如下:
这是我的观点:index.php
<ul class="list-inline">
<?php
if($category->num_rows() > 0)
{
foreach ($category->result() as $row)
{
?>
<li><a href="<?php echo base_url();?>main/getsubcategory<?php $row->id; ?>"><img class="img-responsive center-block" width="80px" src="<?php echo base_url(); ?>assets/admin/uploads/category/<?php echo $row->cat_home_image; ?>" alt="icon" title="icon" class="img-responsive" /><p style="font-size:16px;"><?php echo $row->category_description; ?> </p></a></li>
<?php
}
}
?>
</ul>
这是我的控制器:Main.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
public function index()
{
$this->load->model("category_model");
$data["category"] = $this->category_model->fetch_category();
$this->load->model("ads_model");
$data["ads"] = $this->ads_model->fetch_home_ads();
$this->load->view('index',$data);
//$this->load->view('category');
}
public function getsubcategory()
{
$this->load->model("category_model");
$data["subcategory"] = $this->category_model->fetch_subcategory();
$this->load->view('category',$data);
}
}
这是我的模型:category_model.php
<?php
class Category_model extends CI_Model
{
function fetch_category()
{
$query = $this->db->query("SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id IS NULL && lang_id='1' && c.id!='4' ORDER BY category_description");
return $query;
}
function fetch_subcategory()
{
$subcat = $this->db->query("SELECT * FROM category AS c INNER JOIN category_language AS cl ON c.id=cl.category_id where parent_id='1' && lang_id='1' ORDER BY category_description");
return $subcat;
}
}
?>
如何将类别id传递给模型以获得category_id的适当子类别