我已經在網上搜索了一個很好的答案,但沒有結果。我試圖刪除另一個表中的多行而不是執行該組件的位置。用Joomla刪除另一個表中的多行
基本上,當我刪除組件A中的4行時,這些行也必須在組件B中刪除。該鍵存在於另一個表中,所以這不是問題。我可以很容易地做到這一點與一些快速和骯髒的MySQL查詢,但我想用Joomla的內置方法做到這一點。
在joomla中,從JControllerAdmin中使用delete方法,其中使用getModel獲取模型,然後執行另一個刪除方法。但我似乎無法找到這個刪除方法所在的位置,它實際上刪除了這些行。
順便說一句我有複製粘貼從JControllerAdmin的刪除方法,並將其粘貼在我自己的控制器。我確實改名,但一切正常
所以,現在我已經轉向了Stackoverflow來獲得我的問題的幫助。長話短說:我有一個customDelete()方法,它是從JControllerAdmin類中刪除方法的一個完全相同的副本,我想添加一些功能,使我可以使用customDelete()方法中的id刪除另一個表中的行。
我希望這是明確的:)
謝謝!編輯: 這是控制器中的刪除方法。我必須從#__modeling
刪除所有的行包含的ID(相當於B組份表)內$cid
public function customDelete() {
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
// Get items to remove from the request.
$cid = JRequest::getVar('cid', array(), '', 'array');
if (!is_array($cid) || count($cid) < 1) {
JError::raiseWarning(500, JText::_($this->text_prefix . '_NO_ITEM_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
JArrayHelper::toInteger($cid);
// Remove the items.
if ($model->delete($cid)) {
$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
} else {
$this->setMessage($model->getError());
}
}
是你想從一個JTable刪除表?你當然可以總是使用jdatabasequery來編寫你需要的查詢,但如果它是一個jtable,你可以創建一個實例。 – Elin 2013-04-20 21:51:41