[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_messages 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Messages\Administrator\Controller; 12 13 use Joomla\CMS\Language\Text; 14 use Joomla\CMS\MVC\Controller\BaseController; 15 use Joomla\CMS\Router\Route; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Messages Component Message Model 23 * 24 * @since 1.6 25 */ 26 class ConfigController extends BaseController 27 { 28 /** 29 * Method to save a record. 30 * 31 * @return boolean 32 * 33 * @since 1.6 34 */ 35 public function save() 36 { 37 // Check for request forgeries. 38 $this->checkToken(); 39 40 $model = $this->getModel('Config'); 41 $data = $this->input->post->get('jform', array(), 'array'); 42 43 // Validate the posted data. 44 $form = $model->getForm(); 45 46 if (!$form) { 47 throw new \Exception($model->getError(), 500); 48 } 49 50 $data = $model->validate($form, $data); 51 52 // Check for validation errors. 53 if ($data === false) { 54 // Get the validation messages. 55 $errors = $model->getErrors(); 56 57 // Push up to three validation messages out to the user. 58 for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { 59 if ($errors[$i] instanceof \Exception) { 60 $this->app->enqueueMessage($errors[$i]->getMessage(), 'warning'); 61 } else { 62 $this->app->enqueueMessage($errors[$i], 'warning'); 63 } 64 } 65 66 // Redirect back to the main list. 67 $this->setRedirect(Route::_('index.php?option=com_messages&view=messages', false)); 68 69 return false; 70 } 71 72 // Attempt to save the data. 73 if (!$model->save($data)) { 74 // Redirect back to the main list. 75 $this->setMessage(Text::sprintf('JERROR_SAVE_FAILED', $model->getError()), 'warning'); 76 $this->setRedirect(Route::_('index.php?option=com_messages&view=messages', false)); 77 78 return false; 79 } 80 81 // Redirect to the list screen. 82 $this->setMessage(Text::_('COM_MESSAGES_CONFIG_SAVED')); 83 $this->setRedirect(Route::_('index.php?option=com_messages&view=messages', false)); 84 85 return true; 86 } 87 88 /** 89 * Cancel operation. 90 * 91 * @return void 92 * 93 * @since 4.0.0 94 */ 95 public function cancel() 96 { 97 $this->setRedirect(Route::_('index.php?option=com_messages&view=messages', false)); 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |