Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[SOLVED] How to delete item from DataObject via front end

Go to End

3 Posts   651 Views

Optic Blaze

Community Member, 175 Posts

2 October 2013 at 10:44am

Hi there,

I am trying my hand at some front end forms and i have created a dataobject called Customers.
I can list my customers with the following code in the front end:

// Display list of customers
function ShowCustomers() {
return Customer::get();

But how do i delete a customer? At the moment i have this:

// Delete customer
function DeleteCustomer() {
$SQL_id = (int) $this->ID;
echo $SQL_id;
$page = DataObject::get_by_id('Customer', $SQL_id);



Forum Moderator, 5521 Posts

4 October 2013 at 8:01pm


To delete an object simply called delete. $obj->delete()

Optic Blaze

Community Member, 175 Posts

4 October 2013 at 9:24pm

Thanks Willr,

I did the following and it worked for deleting a record in the customer.php dataobject
//Set permission to allow deletion function below
public static $allowed_actions = array ('delete');

//Delete customer when the following is typed in URL: customer/delete/10 (the record to delete)
public function delete ($request) {
$param = $request->allParams();
$delparam = $param["ID"];