How to delete data from database with CakePHP Framework

In this tutorial I will speak about how to delete data from database by using CakePHP Framework. I suppose you have a model for your table.

If you want to delete data from your database, you can use this code in your controller:

$this->Post->read(null, 1);
$this->Post->delete();

This function will delete all data from your table where id is 1.

If you want to delete all data from a table, you can use this code in your controller:

$this->Post->deleteAll(array('Post.field' => true), false);

You can see how it works in the video bellow:









Leave a Comment