english/administrator/components/com_menus/controllers/menu.php
/**
	 * Method to save a menu item.
	 *
	 * @return	void
	 */
Method to save a menu item.
@return      void
Method to save a menu item . @return void
public function save($key = null, $urlVar = null)
	{
		JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
		$app		= JFactory::getApplication();
		$data		= JRequest::getVar('jform', array(), 'post', 'array');
		$context	= 'com_menus.edit.menu';
		$task		= $this->getTask();
		$recordId	= JRequest::getInt('id');
		if (!$this->checkEditId($context, $recordId)) {
			$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $recordId));
			$this->setMessage($this->getError(), 'error');
			$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
			return false;
		}
		if (isset($data['client_id']) && $data['client_id'] == 1){
			JError::raiseNotice(0, JText::_('COM_MENUS_MENU_TYPE_NOT_ALLOWED'));
			$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
			return false;
		}
		$data['id'] = $recordId;
		$model	= $this->getModel('Menu');
		$form	= $model->getForm();
		if (!$form) {
			JError::raiseError(500, $model->getError());
			return false;
		}
		$data	= $model->validate($form, $data);
		if ($data === false) {
			$errors	= $model->getErrors();
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
			{
				if (JError::isError($errors[$i])) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				}
				else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}
			$app->setUserState('com_menus.edit.menu.data', $data);
			$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
			return false;
		}
		if (!$model->save($data)) {
			$app->setUserState('com_menus.edit.menu.data', $data);
			$this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'warning');
			$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
			return false;
		}
		$this->setMessage(JText::_('COM_MENUS_MENU_SAVE_SUCCESS'));
		switch ($task)
		{
			case 'apply':
				$recordId = $model->getState($this->context.'.id');
				$this->holdEditId($context, $recordId);
				$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit'.$this->getRedirectToItemAppend($recordId), false));
				break;
			case 'save2new':
				$this->releaseEditId($context, $recordId);
				$app->setUserState($context.'.data', null);
				$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
				break;
			default:
				$this->releaseEditId($context, $recordId);
				$app->setUserState($context.'.data', null);
				$this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
				break;
		}
	}
public function save ( $ key = null , $ urlVar = null ) { JRequest :: checkToken ( ) or jexit ( JText :: _ ( 'JINVALID_TOKEN' ) ) ; $ app = JFactory :: getApplication ( ) ; $ data = JRequest :: getVar ( 'jform' , array ( ) , 'post' , 'array' ) ; $ context = 'com_menus.edit.menu' ; $ task = $ this -> getTask ( ) ; $ recordId = JRequest :: getInt ( 'id' ) ; if ( ! $ this -> checkEditId ( $ context , $ recordId ) ) { $ this -> setError ( JText :: sprintf ( 'JLIB_APPLICATION_ERROR_UNHELD_ID' , $ recordId ) ) ; $ this -> setMessage ( $ this -> getError ( ) , 'error' ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=' . $ this -> option . '&view=' . $ this -> view_list . $ this -> getRedirectToListAppend ( ) , false ) ) ; return false ; } if ( isset ( $ data [ 'client_id' ] ) && $ data [ 'client_id' ] == 1 ) { JError :: raiseNotice ( 0 , JText :: _ ( 'COM_MENUS_MENU_TYPE_NOT_ALLOWED' ) ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menu&layout=edit' , false ) ) ; return false ; } $ data [ 'id' ] = $ recordId ; $ model = $ this -> getModel ( 'Menu' ) ; $ form = $ model -> getForm ( ) ; if ( ! $ form ) { JError :: raiseError ( 500 , $ model -> getError ( ) ) ; return false ; } $ data = $ model -> validate ( $ form , $ data ) ; if ( $ data === false ) { $ errors = $ model -> getErrors ( ) ; for ( $ i = 0 , $ n = count ( $ errors ) ; $ i < $ n && $ i < 3 ; $ i ++ ) { if ( JError :: isError ( $ errors [ $ i ] ) ) { $ app -> enqueueMessage ( $ errors [ $ i ] -> getMessage ( ) , 'warning' ) ; } else { $ app -> enqueueMessage ( $ errors [ $ i ] , 'warning' ) ; } } $ app -> setUserState ( 'com_menus.edit.menu.data' , $ data ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menu&layout=edit' , false ) ) ; return false ; } if ( ! $ model -> save ( $ data ) ) { $ app -> setUserState ( 'com_menus.edit.menu.data' , $ data ) ; $ this -> setMessage ( JText :: sprintf ( 'JLIB_APPLICATION_ERROR_SAVE_FAILED' , $ model -> getError ( ) ) , 'warning' ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menu&layout=edit' , false ) ) ; return false ; } $ this -> setMessage ( JText :: _ ( 'COM_MENUS_MENU_SAVE_SUCCESS' ) ) ; switch ( $ task ) { case 'apply' : $ recordId = $ model -> getState ( $ this -> context . '.id' ) ; $ this -> holdEditId ( $ context , $ recordId ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menu&layout=edit' . $ this -> getRedirectToItemAppend ( $ recordId ) , false ) ) ; break ; case 'save2new' : $ this -> releaseEditId ( $ context , $ recordId ) ; $ app -> setUserState ( $ context . '.data' , null ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menu&layout=edit' , false ) ) ; break ; default : $ this -> releaseEditId ( $ context , $ recordId ) ; $ app -> setUserState ( $ context . '.data' , null ) ; $ this -> setRedirect ( JRoute :: _ ( 'index.php?option=com_menus&view=menus' , false ) ) ; break ; } }
Method to save a menu item.
Method to save a menu item .
// Check for request forgeries. // Initialise variables. // Somehow the person just went to the form and saved it - we don't allow that. // Make sure we are not trying to modify an administrator menu. // Redirect back to the edit screen. // Populate the row id from the session. // Get the model and attempt to validate the posted data. // Check for validation errors. // Get the validation messages. // Push up to three validation messages out to the user. // Save the data in the session. // Redirect back to the edit screen. // Attempt to save the data. // Save the data in the session. // Redirect back to the edit screen. // Redirect the user and adjust session state based on the chosen task. // Set the record data in the session. // Redirect back to the edit screen. // Clear the record id and data from the session. // Redirect back to the edit screen. // Clear the record id and data from the session. // Redirect to the list screen.