From Joomla! Documentation

< API16:JControllerForm

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Method to edit an existing record.

<! removed transcluded page call, red link never existed >



Defined in



jimport( 'joomla.application.component.controllerform' );

Source Body

public function edit()
        // Initialise variables.
        $app            = JFactory::getApplication();
        $model          = $this->getModel();
        $table          = $model->getTable();
        $cid            = JRequest::getVar('cid', array(), 'post', 'array');
        $context        = "$this->_option.edit.$this->_context";
        $tmpl           = JRequest::getString('tmpl');
        $layout         = JRequest::getString('layout', 'edit');
        $append         = '';

        // Setup redirect info.
        if ($tmpl) {
                $append .= '&tmpl='.$tmpl;
        if ($layout) {
                $append .= '&layout='.$layout;

        // Get the previous record id (if any) and the current record id.
        $previousId     = (int) $app->getUserState($context.'.id');
        $recordId       = (int) (count($cid) ? $cid[0] : JRequest::getInt('id'));
        $checkin        = property_exists($table, 'checked_out');

        // Access check.
        $key            = $table->getKeyName();
        if (!$this->_allowEdit(array($key => $recordId), $key)) {
                $this->setRedirect(JRoute::_('index.php?option='.$this->_option.'&view='.$this->_view_items, false));
                return JError::raiseWarning(403, 'JERROR_CORE_EDIT_NOT_PERMITTED');

        // If record ids do not match, checkin previous record.
        if ($checkin && ($previousId > 0) && ($recordId != $previousId))
                if (!$model->checkin($previousId))
                        // Check-in failed, go back to the record and display a notice.
                        $message = JText::sprintf('JError_Checkin_failed', $model->getError());
                        $this->setRedirect('index.php?option='.$this->_option.'&view='.$this->_view_item.$append, $message, 'error');
                        return false;

        // Attempt to check-out the new record for editing and redirect.
        if ($checkin && !$model->checkout($recordId))
                // Check-out failed, go back to the list and display a notice.
                $message = JText::sprintf('JError_Checkout_failed', $model->getError());
                $this->setRedirect('index.php?option='.$this->_option.'&view='.$this->_view_item.$append.'&id='.$recordId, $message, 'error');
                return false;
                // Check-out succeeded, push the new record id into the session.
                $app->setUserState($context.'.id',      $recordId);
                $app->setUserState($context.'.data', null);
                return true;

<! removed transcluded page call, red link never existed >


Code Examples