cakePHP不更新记录

cakePHP不更新记录,cakephp,model,controller,Cakephp,Model,Controller,我试图让cakePHP更新数据库中的一条记录,以便创建一条新记录。我的脚本使用“FIRST”进行检查,如果没有返回false,它应该创建一个新记录,否则它应该根据我指定的ID更新现有记录。我在下面故意添加了$this->Asset->id=62;尝试强制更新,但不起作用。有什么帮助吗?(另外,如果您能理解它的作用,请随时用可能更好的代码指导我:)非常新的蛋糕: public function index() { if($this->request->is("pos

我试图让cakePHP更新数据库中的一条记录,以便创建一条新记录。我的脚本使用“FIRST”进行检查,如果没有返回false,它应该创建一个新记录,否则它应该根据我指定的ID更新现有记录。我在下面故意添加了$this->Asset->id=62;尝试强制更新,但不起作用。有什么帮助吗?(另外,如果您能理解它的作用,请随时用可能更好的代码指导我:)非常新的蛋糕:

 public function index() {

        if($this->request->is("post")) {
            $aid = $this->request->data['Asset']['asset_identifier'];
            $type = $this->request->data['Asset']['asset_type_id'];
            $asset = $this->Asset->find("first",array("fields" => array("Asset.id", "Asset.user_id", "Asset.status_id", "Asset.financial_id", "Asset.insurance_id"),"conditions" => array("Asset.asset_identifier" => $aid, "Asset.asset_type_id" => $type)));
            if($asset != false) {
                $uid = $this->Auth->user("id");
                // UPDATE, depends on info:
                $this->Asset->id = $asset['Asset']['id'];
                foreach(array("financial_id", "insurance_id", "user_id") as $value) {
                    if($asset['Asset'][$value] != 0) {
                        $emails[] = $asset['Asset'][$value];
                    }
                }
                if(isset($emails) && count($emails)) {
                    $this->request->data['Asset']['status_id'] = 1;
                    $email = new CakeEmail();
                    $email->from(array('noreply@assetchase.co.za' => 'Assetchase.co.za'));
                    $email->subject('Assetchase.co.za result notification.');
                    foreach($emails as $value) {
                        $user = $this->User->find("first",array("fields" => array("username"),"conditions" => array("id" => $value)));
                        $email->to($user['User']['username']);
                        $email->send('A new notification, booyah!');
                        // Send an email with the username.
                    }
                }
                if($this->Auth->user("user_type_id") == 2) {
                    $this->request->data['Asset']['user_id'] = $uid;
                } elseif($this->Auth->user("user_type_id") == 3) {
                    $this->request->data['Asset']['financial_id'] = $uid;
                } elseif($this->Auth->user("user_type_id") == 4) {
                    $this->request->data['Asset']['insurance_id'] = $uid;
                }
            }
            $this->Asset->id = 62;
            if($this->Asset->saveAll($this->request->data)) {
                $this->Session->setFlash("A new asset has been loaded",'success');
                $this->redirect(array("controller" => "asset", "action" => "thankyou", "guest"));
            } else {
                $this->Session->setFlash('An error has occured.','default',array('class'=>'error'));
            }
        }
        $assetTypes = $this->Asset->AssetType->find('list');
        $this->set("assetTypes", $assetTypes);

    }

当您调用
$this->Asset->saveAll($this->request->data)
时,您告诉Cake获取POST数据并尝试保存它。它根本不查看将ID设置为62的
$this->Asset
。您可以通过检查
var\u dump($this->request->data)
的输出来验证这一点。尝试类似于
$this->request->data['Asset']['id']=62的方法