Php 代码点火器:我能';t从购物车中删除该项目
我试图通过在控制器中发出命令从购物车中删除该项目。这是我的密码:Php 代码点火器:我能';t从购物车中删除该项目,php,codeigniter,Php,Codeigniter,我试图通过在控制器中发出命令从购物车中删除该项目。这是我的密码: function remove($rowid) { $data = array( 'rowid' => $rowid, 'qty' => 0 ); $this->cart->update($data); redirect('bookings'); } 现在,当我点击链接删除该项目时,它返回一个错误“404页面未找到”。以
function remove($rowid) {
$data = array(
'rowid' => $rowid,
'qty' => 0
);
$this->cart->update($data);
redirect('bookings');
}
现在,当我点击链接删除该项目时,它返回一个错误“404页面未找到”。以下是示例URL:
“remove()”函数与我的“add()”位于同一个文件中,它可以正常工作
下面是我的“add()”函数的代码:
public function add()
{
$this->load->model('Bookings_model');
$this->load->helper('url');
$this->load->library('session');
$this->load->library('cart');
$bookings = $this->Bookings_model->get($this->input->post('id'));
$data['type'] = $this->input->post('type');
$data['checkin'] = $this->input->post('checkin');
$data['checkout'] = $this->input->post('checkout');
$data['nights'] = (strtotime($data['checkout']) - strtotime($data['checkin'])) / (60 * 60 * 24);
$insert = array(
'id' => $this->input->post('id'),
'name' => $bookings->room_type,
'checkin' => $data['checkin'],
'checkout' => $data['checkout'],
'nights' => $data['nights'],
'price' => $bookings->default_price,
'qty' => 1,
'amount' => $bookings->default_price
);
$this->cart->insert($insert);
redirect('bookings');
}
我尝试了所有方法,但现在已经两天了,我仍然找不到解决方案。最好使用:
public function delete_item($id)
{
$this->db->where('itemid', $id);
$res = $this->db->delete('mycart');
return $res;
}
在控制器中:
function remove()
{
$result = $this->model_name->delete_item($id);
if($result)
redirect('view or controller');
我们继续直接从模型重定向。可能有时会出错,但大多数情况下会失败。。。
我希望它有用
}
使用此功能从购物车会话中删除项目:
function remove($rowid){
$this->load->library('cart');
$data = array();
foreach($this->cart->contents() as $items){
if($items['rowid'] != $rowid){
$data[] = array('id' => $items['rowid'],
'qty' => $items['qty'],
'price' => $items['price'],
'name' => $items['name']);
}
}
$this->cart->destroy();
$this->cart->insert($data);
redirect('bookings');
}
将产品添加到购物车的url如何?可能应该是
'id'=>$rowid,
@MihaiIorga,这不会导致404。您是否在\uu construct()
中加载了模型?我可以在add()
中看到模型加载函数,但在remove()
中看不到。问题在于我的路线配置:我把$route['bookings/remove']='bookings/remove'但是我没有工作。它应该是“$route['bookings/remove/(:any)”='bookings/remove/$1';”