1
我正在嘗試爲將更新特定建築物的記錄的應用程序添加API調用。這是它的簡單版本,但它似乎沒有做任何事情(包括錯誤)。我錯過了什麼?任何想法都很感激!來自API調用的CakePHP更新記錄
被調用API方法的URL: http://example.com/api/request/UpdateBuilding/<token>/156/The%20Atticus%Building/120%20Finch%20Street%20Monroeville/50830
的法源代碼:
private function UpdateBuilding() {
[email protected]$this->params['pass'][2];
[email protected]$this -> params['pass'][3];
[email protected]$this -> params['pass'][4];
[email protected]$this -> params['pass'][5];
$this->data=array(
"id"=>$buildingId,
"name"=>$name,
"address"=>$address,
"zip_code"=>$zip
);
$this->Building->save($this->data);
}
您應該使用isset()而不是所有在您的代碼中抑制@的值。它更乾淨,更有意義。阻止錯誤可能會導致意外的行爲。 爲了使代碼更具可讀性,你還可以做些什麼,就是使用如下所述的命名參數:http://book.cakephp.org/1.3/view/947/Named-parameters(假設你的語法仍然使用1.3 ) – func0der