Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The main question that you left open is where do you want it to redirect? Joomla by default redirects to the list view (by adding an 's' to the view name unless you specify a list view directly).</p> <p>You can override this in a couple of ways:</p> <p>In your controller (controllers/tireapi.php), set your own list view. I think you can even make this the same view:</p> <pre><code>function __construct() { $this-&gt;view_list = 'tireapi'; parent::__construct(); } </code></pre> <p>Override the save function to change the redirect that happens after save (again in the controller). This works by changing the redirect that happens naturally to something else:</p> <pre><code>public function save($key = null, $urlVar = null) { $return = parent::save($key, $urlVar); $this-&gt;setRedirect(JRoute::_('index.php?option=com_tireapi&amp;view=tireapi')); return $return; } </code></pre> <p>One of those should do the trick for you. </p> <p>** UPDATE</p> <p>To get the item to checkout initially you will want to change how your component handles no view being set. Right now you just set the view, instead, let's redirect! Updated controller.php is below.</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla controller library jimport('joomla.application.component.controller'); class TireAPIController extends JController{ function display($cachable = false){ // set default view if not set $input = JFactory::getApplication()-&gt;input; $view = $input-&gt;get('view'); if (!$view) { JFactory::getApplication()-&gt;redirect('index.php?option=com_tireapi&amp;task=tireapi.edit&amp;id=1'); exit(); } // call parent behavior parent::display($cachable); } } ?&gt; </code></pre> <p>NOTE: This will work really poorly if more than one person needs to edit this, since the system checks it out when you open the component if you also have it redirect back to this page after saving. Because then it will always be checked out to the last person that edited it so the next person won't be able to open it. If only one person edits it, it will be fine.</p> <p>SECOND NOTE: If you don't want to hack the checkout system you can also ignore it during the save process, which is basically the same level of hacking.</p> <p>Below is a copy of the save function from controllerform.php in <code>libraries/joomla/application/component/</code>. This is what is running on save normally (because of where you inherit from. I have removed the check if the item is checked out. So if you put this in your tireapi.php controller where the <code>parent::save...</code> bit is, it will run instead and you don't have to bother with checking the item out (i.e. ignore all the comments...). (Honestly, in your case, you can probably delete a lot more of this, but this is what is happening on save, btw!)</p> <pre><code>public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $app = JFactory::getApplication(); $lang = JFactory::getLanguage(); $model = $this-&gt;getModel(); $table = $model-&gt;getTable(); $data = JRequest::getVar('jform', array(), 'post', 'array'); $checkin = property_exists($table, 'checked_out'); $context = "$this-&gt;option.edit.$this-&gt;context"; $task = $this-&gt;getTask(); // Determine the name of the primary key for the data. if (empty($key)) { $key = $table-&gt;getKeyName(); } // To avoid data collisions the urlVar may be different from the primary key. if (empty($urlVar)) { $urlVar = $key; } $recordId = JRequest::getInt($urlVar); // Populate the row id from the session. $data[$key] = $recordId; // The save2copy task needs to be handled slightly differently. if ($task == 'save2copy') { // Check-in the original row. if ($checkin &amp;&amp; $model-&gt;checkin($data[$key]) === false) { // Check-in failed. Go back to the item and display a notice. $this-&gt;setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model-&gt;getError())); $this-&gt;setMessage($this-&gt;getError(), 'error'); $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend($recordId, $urlVar), false ) ); return false; } // Reset the ID and then treat the request as for Apply. $data[$key] = 0; $task = 'apply'; } // Access check. if (!$this-&gt;allowSave($data, $key)) { $this-&gt;setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED')); $this-&gt;setMessage($this-&gt;getError(), 'error'); $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_list . $this-&gt;getRedirectToListAppend(), false ) ); return false; } // Validate the posted data. // Sometimes the form needs some posted data, such as for plugins and modules. $form = $model-&gt;getForm($data, false); if (!$form) { $app-&gt;enqueueMessage($model-&gt;getError(), 'error'); return false; } // Test whether the data is valid. $validData = $model-&gt;validate($form, $data); // Check for validation errors. if ($validData === false) { // Get the validation messages. $errors = $model-&gt;getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i &lt; $n &amp;&amp; $i &lt; 3; $i++) { if ($errors[$i] instanceof Exception) { $app-&gt;enqueueMessage($errors[$i]-&gt;getMessage(), 'warning'); } else { $app-&gt;enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $app-&gt;setUserState($context . '.data', $data); // Redirect back to the edit screen. $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend($recordId, $urlVar), false ) ); return false; } // Attempt to save the data. if (!$model-&gt;save($validData)) { // Save the data in the session. $app-&gt;setUserState($context . '.data', $validData); // Redirect back to the edit screen. $this-&gt;setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model-&gt;getError())); $this-&gt;setMessage($this-&gt;getError(), 'error'); $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend($recordId, $urlVar), false ) ); return false; } // Save succeeded, so check-in the record. if ($checkin &amp;&amp; $model-&gt;checkin($validData[$key]) === false) { // Save the data in the session. $app-&gt;setUserState($context . '.data', $validData); // Check-in failed, so go back to the record and display a notice. $this-&gt;setError(JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model-&gt;getError())); $this-&gt;setMessage($this-&gt;getError(), 'error'); $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend($recordId, $urlVar), false ) ); return false; } $this-&gt;setMessage( JText::_( ($lang-&gt;hasKey($this-&gt;text_prefix . ($recordId == 0 &amp;&amp; $app-&gt;isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS') ? $this-&gt;text_prefix : 'JLIB_APPLICATION') . ($recordId == 0 &amp;&amp; $app-&gt;isSite() ? '_SUBMIT' : '') . '_SAVE_SUCCESS' ) ); // Redirect the user and adjust session state based on the chosen task. switch ($task) { case 'apply': // Set the record data in the session. $recordId = $model-&gt;getState($this-&gt;context . '.id'); $this-&gt;holdEditId($context, $recordId); $app-&gt;setUserState($context . '.data', null); $model-&gt;checkout($recordId); // Redirect back to the edit screen. $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend($recordId, $urlVar), false ) ); break; case 'save2new': // Clear the record id and data from the session. $this-&gt;releaseEditId($context, $recordId); $app-&gt;setUserState($context . '.data', null); // Redirect back to the edit screen. $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_item . $this-&gt;getRedirectToItemAppend(null, $urlVar), false ) ); break; default: // Clear the record id and data from the session. $this-&gt;releaseEditId($context, $recordId); $app-&gt;setUserState($context . '.data', null); // Redirect to the list screen. $this-&gt;setRedirect( JRoute::_( 'index.php?option=' . $this-&gt;option . '&amp;view=' . $this-&gt;view_list . $this-&gt;getRedirectToListAppend(), false ) ); break; } // Invoke the postSave method to allow for the child class to access the model. $this-&gt;postSaveHook($model, $validData); return true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload