Actions

API16

JControllerForm/edit

From Joomla! Documentation

< API16:JControllerForm
Revision as of 21:57, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Method to edit an existing record.

[<! removed edit link to red link >]

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

Syntax

edit()


Defined in

libraries/joomla/application/component/controllerform.php

Importing

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;
        }
        else
        {
                // Check-out succeeded, push the new record id into the session.
                $app->setUserState($context.'.id',      $recordId);
                $app->setUserState($context.'.data', null);
                $this->setRedirect('index.php?option='.$this->_option.'&view='.$this->_view_item.$append);
                return true;
        }
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />