Form Controller

It is a method to add a new record.

  • return boolean - True if the record can be added, false if not.
public function add()
{
$context = "$this->option.edit.$this->context";

// Access check.
if (!$this->allowAdd())
{
// Set the internal error and also the redirect error.
$this->setError(\JText::_('JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');

$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend(), false
)
);

return false;
}

// Clear the record edit information from the session.
\JFactory::getApplication()->setUserState($context . '.data', null);

// Redirect to the edit screen.
$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend(), false
)
);

return true;
}

The allowAdd() Method

This method is used by the add() to check if you can add a new record. Extended classes can override this if necessary.

  • array $data - An array of input data.
  • return boolean
protected function allowAdd($data = array())
{
$user = \JFactory::getUser();

return $user->authorise('core.create', $this->option) || count($user->getAuthorisedCategories($this->option, 'core.create'));
}