API16:JControllerForm/edit
From Joomla! Documentation
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.
Description:JControllerForm/edit
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; } }
[Edit See Also] SeeAlso:JControllerForm/edit
Examples
<CodeExamplesForm />
