english/libraries/joomla/application/component/controllerform.php
/**
	 * Method to edit an existing record.
	 *
	 * @param   string  $key     The name of the primary key of the URL variable.
	 * @param   string  $urlVar  The name of the URL variable if different from the primary key
	 *                           (sometimes required to avoid router collisions).
	 *
	 * @return  boolean  True if access level check and checkout passes, false otherwise.
	 * @since   11.1
	 */
Method to edit an existing record.
@param   string  $key     The name of the primary key of the URL variable.
@param   string  $urlVar  The name of the URL variable if different from the primary key
(sometimes required to avoid router collisions).

@return  boolean  True if access level check and checkout passes, false otherwise.
Method to edit an existing record . @param string $key The name of the primary key of the URL variable . @param string $urlVar The name of the URL variable if different from the primary key ( sometimes required to avoid router collisions ) . @return boolean True if access level check and checkout passes false otherwise .
public function edit($key = null, $urlVar = null)
	{
		$app		= JFactory::getApplication();
		$model		= $this->getModel();
		$table		= $model->getTable();
		$cid		= JRequest::getVar('cid', array(), 'post', 'array');
		$context	= "$this->option.edit.$this->context";
		$append		= '';
		if (empty($key)) {
			$key = $table->getKeyName();
		}
		if (empty($urlVar)) {
			$urlVar = $key;
		}
		$recordId	= (int) (count($cid) ? $cid[0] : JRequest::getInt($urlVar));
		$checkin	= property_exists($table, 'checked_out');
		if (!$this->allowEdit(array($key => $recordId), $key)) {
			$this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
			return false;
		}
		if ($checkin && !$model->checkout($recordId)) {
			$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKOUT_FAILED', $model->getError()));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, $urlVar));
			return false;
		}
		else {
			$this->holdEditId($context, $recordId);
			$app->setUserState($context.'.data', null);
			$this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, $urlVar));
			return true;
		}
	}
public function edit ( $ key = null , $ urlVar = null ) { $ app = JFactory :: getApplication ( ) ; $ model = $ this -> getModel ( ) ; $ table = $ model -> getTable ( ) ; $ cid = JRequest :: getVar ( 'cid' , array ( ) , 'post' , 'array' ) ; $ context = " $ this -> option .edit. $ this -> context " ; $ append = '' ; if ( empty ( $ key ) ) { $ key = $ table -> getKeyName ( ) ; } if ( empty ( $ urlVar ) ) { $ urlVar = $ key ; } $ recordId = ( int ) ( count ( $ cid ) ? $ cid [ 0 ] : JRequest :: getInt ( $ urlVar ) ) ; $ checkin = property_exists ( $ table , 'checked_out' ) ; if ( ! $ this -> allowEdit ( array ( $ key => $ recordId ) , $ key ) ) { $ this -> setError ( JText :: _ ( 'JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED' ) ) ; $ this -> setMessage ( $ this -> getError ( ) , 'error' ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=' . $ this -> option . '&view=' . $ this -> view_list . $ this -> getRedirectToListAppend ( ) , false ) ) ; return false ; } if ( $ checkin && ! $ model -> checkout ( $ recordId ) ) { $ this -> setError ( JText :: sprintf ( 'JLIB_APPLICATION_ERROR_CHECKOUT_FAILED' , $ model -> getError ( ) ) ) ; $ this -> setMessage ( $ this -> getError ( ) , 'error' ) ; $ this -> setRedirect ( 'index.php?option=' . $ this -> option . '&view=' . $ this -> view_item . $ this -> getRedirectToItemAppend ( $ recordId , $ urlVar ) ) ; return false ; } else { $ this -> holdEditId ( $ context , $ recordId ) ; $ app -> setUserState ( $ context . '.data' , null ) ; $ this -> setRedirect ( 'index.php?option=' . $ this -> option . '&view=' . $ this -> view_item . $ this -> getRedirectToItemAppend ( $ recordId , $ urlVar ) ) ; return true ; } }
Method to edit an existing record.
Method to edit an existing record .
// Initialise variables. // Determine the name of the primary key for the data. // To avoid data collisions the urlVar may be different from the primary key. // Get the previous record id (if any) and the current record id. // Access check. // Attempt to check-out the new record for editing and redirect. // Check-out failed, display a notice but allow the user to see the record. // Check-out succeeded, push the new record id into the session.