0
我想刪除一個id數組,當它被刪除時,我想上傳的圖片與它關聯也使用unlink刪除。我在Joomla的admin mvc組件中使用joomla和mysql。從joomla中刪除上傳的文件時,它們是否被刪除?
我對控制器刪除代碼具有如下:
function remove()
{
$arrayIDs = JRequest::getVar ('cid', null, 'default', 'array');
//Reads cid as an array
$model = & $this->getModel ('greetings');
jimport ('joomla.filesystem.file');
if (is_array ($arrayIDs) && count ($arrayIDs) > 0) {
foreach ($arrayIDs as $k => $id) {
$del = $model->deleteGreetings ($arrayIDs);
if ($del) {
$getdeleted = $model->getUploadpic ($id);
$deletefile = JPATH_COMPONENT . DS . "uploads" . DS . $uploadedfile;
unlink ($deletefile);
}
}
}
if ($arrayIDs === null) { //Make sure the cid parameter was in the request
JError::raiseError (500, 'cid parameter missing from the request');
}
$redirectTo = JRoute::_ ('index.php?option=' . JRequest::getVar ('option'));
$this->setRedirect ($redirectTo, 'Deleted...');
}
...和模型我的代碼是:
function deleteGreetings($arrayIDs) {
$query = "DELETE FROM #__greetings WHERE id IN (" . implode (',', $arrayIDs) . ")";
$db = $this->getDBO();
$db->setQuery ($query);
if (! $db->query()) {
$errorMessage = $this->getDBO()->getErrorMsg();
JError::raiseError (500, 'Error deleting greetings: ' . $errorMessage);
} else {
return TRUE;
}
}
這是一個較舊的答案,我想補充一點,你不應該使用JRequest或JError更多,因爲他們已經被棄用。 – Elin