Deleting Data
View alone
delete
To delete a specific record, pass its ID to delete()
.
<?php
class AdminVenuesController extends MvcAdminController {
public function delete() {
$this->set_object();
if (!empty($this->object)) {
$this->Venue->delete($this->params['id']);
$this->flash('notice', 'Successfully deleted!');
} else {
$this->flash('warning', 'A venue with ID "'.$this->params['id'].'" couldn\'t be found.');
}
$url = MvcRouter::admin_url(array('controller' => $this->name, 'action' => 'index'));
$this->redirect($url);
}
}
?>
View alone
delete_all
To delete all records that match given conditions, use delete_all()
.
<?php
class Event extends MvcModel {
public function delete_past_events() {
$this->delete_all( array(
'conditions' => array('date <' => date('Y-m-d')
))
);
}
}
?>