簡體   English   中英

帶有datamapper的Codeigniter保存錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM