DELETE を使って指定行を削除する。
■Model
Model はそのまま
■Controller
/Test/delete?id=10 とか /Test/delete/10 で削除できるようにしておく。
in Controller/TestController.php
1 2 3 4 5 6 7 8 | public function delete ( $id =null) { if (isset( $this ->params[ 'url' ][ 'id' ])) $id = $this ->params[ 'url' ][ 'id' ]; if ( $id != null ) { // $this->Test->read(null, $id); $this ->Test-> delete ( $id ); } $this ->set( 'Test' , $this ->Test->find( 'all' )); } |
delete で削除する。read は必要ないみたい…あとでチェックする。
■View
View は同じ
■結果
削除した結果が表示される。
※DELETEする前に COUNT しているのが謎だが…後で調べる。マッチする行がない場合には、DELETE が呼び出されないみたい。