[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_categories/src/Controller/ -> DisplayController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_categories
   6   *
   7   * @copyright   (C) 2008 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\Categories\Administrator\Controller;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\Controller\BaseController;
  16  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  17  use Joomla\CMS\Router\Route;
  18  use Joomla\Input\Input;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Categories view class for the Category package.
  26   *
  27   * @since  1.6
  28   */
  29  class DisplayController extends BaseController
  30  {
  31      /**
  32       * The default view.
  33       *
  34       * @var    string
  35       * @since  1.6
  36       */
  37      protected $default_view = 'categories';
  38  
  39      /**
  40       * The extension for which the categories apply.
  41       *
  42       * @var    string
  43       * @since  1.6
  44       */
  45      protected $extension;
  46  
  47      /**
  48       * Constructor.
  49       *
  50       * @param   array                     $config   An optional associative array of configuration settings.
  51       * @param   MVCFactoryInterface|null  $factory  The factory.
  52       * @param   CMSApplication|null       $app      The Application for the dispatcher
  53       * @param   Input|null                $input    Input
  54       *
  55       * @since   3.0
  56       */
  57      public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
  58      {
  59          parent::__construct($config, $factory, $app, $input);
  60  
  61          // Guess the Text message prefix. Defaults to the option.
  62          if (empty($this->extension)) {
  63              $this->extension = $this->input->get('extension', 'com_content');
  64          }
  65      }
  66  
  67      /**
  68       * Method to display a view.
  69       *
  70       * @param   boolean  $cachable   If true, the view output will be cached
  71       * @param   array    $urlparams  An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}.
  72       *
  73       * @return  static|boolean  This object to support chaining.
  74       *
  75       * @since   1.5
  76       */
  77      public function display($cachable = false, $urlparams = array())
  78      {
  79          // Get the document object.
  80          $document = $this->app->getDocument();
  81  
  82          // Set the default view name and format from the Request.
  83          $vName   = $this->input->get('view', 'categories');
  84          $vFormat = $document->getType();
  85          $lName   = $this->input->get('layout', 'default', 'string');
  86          $id      = $this->input->getInt('id');
  87  
  88          // Check for edit form.
  89          if ($vName == 'category' && $lName == 'edit' && !$this->checkEditId('com_categories.edit.category', $id)) {
  90              // Somehow the person just went to the form - we don't allow that.
  91              if (!\count($this->app->getMessageQueue())) {
  92                  $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error');
  93              }
  94  
  95              $this->setRedirect(Route::_('index.php?option=com_categories&view=categories&extension=' . $this->extension, false));
  96  
  97              return false;
  98          }
  99  
 100          // Get and render the view.
 101          if ($view = $this->getView($vName, $vFormat)) {
 102              // Get the model for the view.
 103              $model = $this->getModel($vName, 'Administrator', array('name' => $vName . '.' . substr($this->extension, 4)));
 104  
 105              // Push the model into the view (as default).
 106              $view->setModel($model, true);
 107              $view->setLayout($lName);
 108  
 109              // Push document object into the view.
 110              $view->document = $document;
 111              $view->display();
 112          }
 113  
 114          return $this;
 115      }
 116  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer