phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - MVC: Adding Delete Function at Back-End

Tag: joomla, MVC, pattern, component, back-end   Category: PHP Framework
post: 07 Feb 2008 read: 469


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

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting