[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/MVC/View/ -> JsonView.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\MVC\View;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Base class for a Joomla Json View
  18   *
  19   * Class holding methods for displaying presentation data.
  20   *
  21   * @since  4.0.0
  22   */
  23  class JsonView extends AbstractView
  24  {
  25      /**
  26       * The base path of the view
  27       *
  28       * @var    string
  29       * @since  4.0.0
  30       */
  31      protected $_basePath = null;
  32  
  33      /**
  34       * Charset to use in escaping mechanisms; defaults to urf8 (UTF-8)
  35       *
  36       * @var    string
  37       * @since  4.0.0
  38       */
  39      protected $_charset = 'UTF-8';
  40  
  41      /**
  42       * The output of the view.
  43       *
  44       * @var    array
  45       * @since  4.0.0
  46       */
  47      protected $_output = array();
  48  
  49      /**
  50       * Constructor
  51       *
  52       * @param   array  $config  A named configuration array for object construction.
  53       *                          name: the name (optional) of the view (defaults to the view class name suffix).
  54       *                          charset: the character set to use for display
  55       *                          escape: the name (optional) of the function to use for escaping strings
  56       *                          base_path: the parent path (optional) of the views directory (defaults to the component folder)
  57       *                          template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name
  58       *                          helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/)
  59       *                          layout: the layout (optional) to use to display the view
  60       *
  61       * @since   4.0.0
  62       */
  63      public function __construct($config = array())
  64      {
  65          parent::__construct($config);
  66  
  67          // Set the charset (used by the variable escaping functions)
  68          if (\array_key_exists('charset', $config)) {
  69              @trigger_error(
  70                  'Setting a custom charset for escaping is deprecated. Override \JViewLegacy::escape() instead.',
  71                  E_USER_DEPRECATED
  72              );
  73              $this->_charset = $config['charset'];
  74          }
  75  
  76          // Set a base path for use by the view
  77          if (\array_key_exists('base_path', $config)) {
  78              $this->_basePath = $config['base_path'];
  79          } else {
  80              $this->_basePath = JPATH_COMPONENT;
  81          }
  82      }
  83  
  84      /**
  85       * Execute and display a template script.
  86       *
  87       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  88       *
  89       * @return  void
  90       *
  91       * @since   4.0.0
  92       */
  93      public function display($tpl = null)
  94      {
  95          // Serializing the output
  96          $result = json_encode($this->_output);
  97  
  98          // Pushing output to the document
  99          $this->document->setBuffer($result);
 100      }
 101  }


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