After adding later, do not fix it delete the data.
- Modify the files in the folder hello.php controllers add method delete.
com_helloworld/controllers/hello.php
function delete()
{
JRequest::checkToken() or die('Invaild Token');
$cid = JRequest::getVar('cid');
$model = $this->getModel('hello');
foreach ($cid as $id) {
if($model->delete($id)) {
$this->setMessage('Delete successfully');
} else {
JError::raiseWarning('', 'Delete failed<br />'.implode('<br />', $model->getErrors()));
}
}
$this->setRedirect(JRoute::_('index.php?option=com_helloworld&c=hello'));
}
- Modify the files in the folder models hello.php Add method delete.
com_helloworld/models/hello.php
function delete($id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
try {
$query->delete('#__helloworld_hello')
->where($db->quoteName('id').'='.$db->quote($id));
$db->setQuery($query);
$db->execute();
} catch (RuntimeException $exc) {
$this->setError($exc->getMessage());
return false;
}
return true;
}