phpeveryday.com

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


Joomla - Component: Deleting Data

Tag: joomla, cms, Joomla Component   Category: PHP Framework
post: 06 Nov 2007 read: 3,355


It is realy easy for adding delete functionality in Joomla! Follow this steps:

  1. Open "admin.hello.php" file, add following bold code:
    
    switch($task){
    
      case 'edit':
        editHello();
        break;
    
      case 'add':
        addHello();
        break;
    		
      case 'cancel';		
        showHello();
        break;
    		
      case 'save';	
        case 'apply';			
        saveHello();
        break;	
    
      // This will work when you set task to 'remove
      case 'remove':
        removeHello();
        break;
    		
    		
      default:
        showHello();
        break;
    
    }
    
  2. Add removeHello() function like following code:
    
    function removeHello()
    {
    
      global $mainframe;
      // Initialize variables	
      $db =& JFactory::getDBO();
      // Define cid array variable
      $cid = JRequest::getVar( 'cid' , array() , '' , 'array' );
      // Make sure cid array variable content integer format
      JArrayHelper::toInteger($cid);
    
      // If any item selected
      if (count( $cid )) {
        // Prepare sql statement, if cid array more than one, 
        // will be "cid1, cid2, ..."
        $cids = implode( ',', $cid );
        // Create sql statement
        $query = 'DELETE FROM #__hello'
        . ' WHERE id IN ( '. $cids .' )'
        ;
        // Execute query
        $db->setQuery( $query );
        if (!$db->query()) {
          echo "<script> alert('".$db->getErrorMsg(true)."'); 
          window.history.go(-1); </script>\n";
        }
      }
    
      // After all, redirect again to frontpage
      $mainframe->redirect( "index.php?option=com_hello" );
    }
    


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming

| 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