Joomla - MVC: Adding Delete Function at Back-End



Joomla Back End MVC Step by Step Tutorial - Part 9: After add save and edit function, now, we add delete function at back-end. For this job, we just edit controller.

Open "controller.php". Add remove function like this:

joomla mvc back end delete function

function remove()
  {
  	global $option;
	
	$db =& JFactory::getDBO();
	
	$cid = JRequest::getVar( 'cid' , array() , '' , 'array' );
	JArrayHelper::toInteger($cid);

	if (count( $cid )) {
		$cids = implode( ',', $cid );
		$query = 'DELETE FROM #__hello'
		. ' WHERE id IN ( '. $cids .' )';
		
		$db->setQuery( $query );
		if (!$db->query()) {
			echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
		}
	}	
	
	$this->setRedirect ( 'index.php?option=' .$option );
  }


Series this article:
Joomla - MVC: Reorganizing Back End Code
Joomla - MVC: Creating Controller and Model for Back End
Joomla - MVC: Creating View for Back End
Joomla - MVC: Adding Pagination for Back End
Joomla - MVC: Adding Element Paginating for Back End
Joomla - MVC: Creating Form Input Data for Back-End
Joomla - MVC: Saving Data for Back End
Joomla - MVC: Editing Data for Back-End
Joomla - MVC: Adding Delete Function at Back-End
Joomla - MVC: Controlling Publish State for Back-End


Tag: joomla, MVC, pattern, component, back-end Category: PHP Framework Post : February 07th 2008 Read: 2,675 Bookmark and Share

blog comments powered by Disqus