cake php在尝试从sql server中删除记录时返回错误500

时间:2017-07-07 08:57:34

标签: php jquery mysql cakephp

控制器:

public function delete_saldo($id = null)
    {
     if($this->Auth->user('role') !== 'admin'){
         return $this->redirect(['controller' => 'Reparti', 'action' => 'index']);
     }else {
         $this->request->allowMethod(['post', 'delete']);
         $saldiMagazzino = $this->SaldiMagazzino->find('all',['conditions' => ['ID_SALDO = ' => $id]]);
            if ($this->SaldiMagazzino->delete($saldiMagazzino)) {
                $message = 'Saved';
            } else {
                $message = 'Error';
            }
            $this->set([
                'message' => $message,
                '_serialize' => ['message']
            ]);
        }
    }

jquery的:

 function deleteLotto(id_Saldo) {

        $.ajax({
            type: "DELETE",
            url: "/api/saldi_magazzino/deleteSaldo/"+id_Saldo+".json",
            cache: false,
            dataType: "json",
        });

    }

路由器:

$routes->resources('SaldiMagazzino', [
        'map'=>[
            'deleteSaldo/:id'=>[
                'action' => 'delete_saldo',
                'method' => 'DELETE'
            ]
        ]
    ]);

当我尝试执行此操作时,会出现内部服务器错误500。 DB是一个mysql服务器。这是在蛋糕php V 0.2.9

上运行

编辑:添加路由器。忘记了

编辑:当我尝试执行该功能时,这就是调用失败的方式:

    Request URL:http://localhost/api/saldi_magazzino/deleteSaldo/200.json
Request Method:DELETE
Status Code:500 Internal Server Error
Remote Address:127.0.0.1:80
Response Headers
view parsed
HTTP/1.1 500 Internal Server Error
Date: Fri, 07 Jul 2017 12:03:01 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.21
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 121
Connection: close
Content-Type: application/json; charset=UTF-8
Request Headers
view parsed
DELETE /api/saldi_magazzino/deleteSaldo/200.json HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Referer: http://localhost/index.php/articoli/check_magazzino
Accept-Encoding: gzip, deflate, sdch
Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: _ga=GA1.1.404341568.1456939522; Webstorm-edbc5810=5f1b2a4a-2e60-4ec4-a544-13a4735b30dd; CAKEPHP=jlbdjed9d109qbdpfp1slh9ar3

0 个答案:

没有答案