【发布时间】:2013-06-30 06:36:42
【问题描述】:
Codeigniter 未定义索引网上商店:
由于某种原因,我返回“未定义的索引:在控制器中分组。
我已经添加了控制器和下面的模型。
我也刚刚添加了 getProduct() 代码
/*Here is my model*/
function getProductsByGroup($limit,$group,$skip){
$data = array();
if ($limit == 0){
$limit=3;
}
$this->db->select('id,name,shortdesc,thumbnail');
$this->db->where('grouping', $group);
$this->db->where('status', 'active');
$this->db->where('id !=', ($skip));
$this->db->order_by('name','asc');
$this->db->limit($limit);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
/*getProduct()*/
function getProduct($id){
$data = array();
$option = array('id' => $id);
/*pass the id and other options to the category*/
$Q = $this->db->get_where("categories",$option,1);
if ($Q ->num_rows() > 0){
$data = $Q->row_array();
}
$Q->free_result();
return $data;
}
/*This is my controller*/
public function product($id)
{
$product = $this->MProducts->getProduct($id);
if (!count($product))
{
redirect('welcome/index','refresh');
}
/* This is where the error is coming from*/
$data['grouplist'] = $this->MProducts->getProductsByGroup(3,$product['grouping'],$id);
$data['product'] = $product;
$data['title'] = "Claudia’s Kids | ". $product['name'];
$data['main'] = 'product';
$data['navlist'] = $this->MCats->getCategoriesNav();
$this->load->vars($data);
$this->load->view('template');
}
【问题讨论】:
-
在您的问题中发布
getProduct()的代码 -
我刚刚做到了。谢谢
-
做一个 print_r($product);死();在您设置 $product 变量之后...查看 $product['grouping'] 是否为空。错误表明 $product['grouping'] 丢失
-
我在这段代码 ($product = $this->MProducts->getProduct($id);) 之后做了一个 foreach 语句,它看起来很好,我可以获得产品 id...
标签: php codeigniter undefined-index