Joomla - Component: Adding Comment ( Insert Data )


Now, we try to write code for inserting comment. For this task, we add case "comment" at hello.php. Follow this steps:

  1. Open "hello.php" within joomla/administrator. Insert following bold code:
    switch( $task ){
    	case 'view':
    		viewHello($option);
    		break;
    	
    	case 'comment':
    		addComment($option);
    		break;
    
    	default:
    		showPublishedHello($option);
    		break;
    }
    
  2. Insert following function:
    function addComment($option)
    {
      global $mainframe;
      $row =& JTable::getInstance( 'comment' , 'Table' );
      if (!$row->bind(JRequest::get( 'post' )))
      {
        JError::raiseError(500, $row->getError() );
      }
    	
      $row->comment_date = date ( 'Y-m-d H:i:s' );
    	
      $user =& JFactory::getUser();
    	
      if($user->id)
      {
        $row->user_id = $user->id;
      }
    	
      if(!$row->store())
      {
        JError::raiseError(500, $row->getError() );
      }
    
      $link = JRoute::_( 'index.php?option='.$option.'&id='.$row->id . '&task=view' );
      $mainframe->redirect( $link, 'Comment Added' );
    	
    }
    


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

Bookmark and Share Tag: joomla, cms Category: PHP Framework Post : November 13th 2007 Read: 51,967

advertisements


blog comments powered by Disqus