public function display($cachable = false, $urlparams = false, $tpl = null)
{
$document = $this->container->platform->getDocument();
if ($document instanceof \JDocument) {
$viewType = $document->getType();
} else {
$viewType = $this->input->getCmd('format', 'html');
}
$view = $this->getView();
$view->setTask($this->task);
$view->setDoTask($this->doTask);
// Get/Create the model
if ($model = $this->getModel()) {
// Push the model into the view (as default)
$view->setDefaultModel($model);
}
// Set the layout
if (!is_null($this->layout)) {
$view->setLayout($this->layout);
}
$conf = $this->container->platform->getConfig();
if ($this->container->platform->isFrontend() && $cachable && $viewType != 'feed' && $conf->get('caching') >= 1) {
// Get a JCache object
$option = $this->input->get('option', 'com_foobar', 'cmd');
$cache = \JFactory::getCache($option, 'view');
// Set up a cache ID based on component, view, task and user group assignment
$user = $this->container->platform->getUser();
if ($user->guest) {
$groups = array();
} else {
$groups = $user->groups;
}
$importantParameters = array();
// Set up safe URL parameters
if (!is_array($urlparams)) {
$urlparams = array('option' => 'CMD', 'view' => 'CMD', 'task' => 'CMD', 'format' => 'CMD', 'layout' => 'CMD', 'id' => 'INT');
}
if (is_array($urlparams)) {
/** @var \JApplicationCms $app */
$app = \JFactory::getApplication();
$registeredurlparams = null;
if (!empty($app->registeredurlparams)) {
$registeredurlparams = $app->registeredurlparams;
} else {
$registeredurlparams = new \stdClass();
}
foreach ($urlparams as $key => $value) {
// Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
$registeredurlparams->{$key} = $value;
// Add the URL-important parameters into the array
$importantParameters[$key] = $this->input->get($key, null, $value);
}
$app->registeredurlparams = $registeredurlparams;
}
// Create the cache ID after setting the registered URL params, as they are used to generate the ID
$cacheId = md5(serialize(array(\JCache::makeId(), $view->getName(), $this->doTask, $groups, $importantParameters)));
// Get the cached view or cache the current view
$cache->get($view, 'display', $cacheId);
} else {
// Display without caching
$view->display($tpl);
}
}