[英]Codeigniter with datamapper save error
所以我试图为我的应用制作CRUD。 我已经设置了一个控制器,像这样:
class Clients extends CI_Controller {
public function __construct() {
parent::__construct();
session_start();
$this->c = new Client();
$this->u = new User();
}
function index() {
$data['current_view'] = 'client_view';
$data['header'] = 'Меню клиентов';
$data['clients'] = $this->getClients();
$this->load->view('main_view',$data);
}
function getClients() {
$this->u->where('username',$_SESSION['username'])->get();
$c = $this->c->where('user_id',$this->u->id)->get();
return $c;
}
function delClient() {
$this->c->where('client_id', $this->uri->segment(3))->delete();
$this->c->skip_validation()->save();
$this->index();
}
}
但是,当我尝试在客户端上执行删除时,出现数据库错误:
您必须使用“设置”方法来更新条目。
文件名:C:\\ OpenServer \\ domains \\ localhost \\ system \\ database \\ DB_active_rec.php
行号:1174
这可能是什么原因? 我在这里找到了类似的问题,但事实并非如此。
编辑:客户端模型:
class Client extends DataMapper {
public $has_one = array('user');
public function __construct($id = NULL) {
parent::__construct($id);
}
}
您尚未将uri段传递给函数delClient()
,这是您的模型...
function delClient($id) {
//$id is the value which you want to delete
$this->c->where('client_id', $id)->delete();
$this->c->skip_validation()->save();
$this->index();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.