API16

JControllerForm/cancel: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
Method to cancel an edit  
Method to cancel an edit  


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>


<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >
Line 63: Line 61:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
<! removed transcluded page call, red link never existed >
<! removed transcluded page call, red link never existed >


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=cancel
  category=cancel
  category=JControllerForm
  category=JControllerForm
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 01:25, 25 March 2017

Description

Method to cancel an edit


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

Syntax

cancel()


Defined in

libraries/joomla/application/component/controllerform.php

Importing

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

Source Body

public function cancel()
{
        JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));

        // Initialise variables.
        $app            = JFactory::getApplication();
        $model          = &$this->getModel();
        $table          = $model->getTable();
        $checkin        = property_exists($table, 'checked_out');
        $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 record id.
        $recordId = (int) $app->getUserState($context.'.id');

        // Attempt to check-in the current record.
        if ($checkin && $recordId)
        {
                if(!$model->checkin($recordId))
                {
                        // 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;
                }
        }

        // Clean the session data and redirect.
        $app->setUserState($context.'.id',              null);
        $app->setUserState($context.'.data',    null);
        $this->setRedirect(JRoute::_('index.php?option='.$this->_option.'&view='.$this->_view_list, false));
}


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

Examples

Code Examples