Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Last active October 27, 2018 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/6089087 to your computer and use it in GitHub Desktop.
Save dongilbert/6089087 to your computer and use it in GitHub Desktop.
Joomla getName() method to strip format from returned view name.
<?php
class JModelLegacy
{
/**
* Method to get the view name
*
* The view name by default parsed using the classname, or it can be set
* by passing a $config['name'] in the class constructor
*
* @return string The name of the view
*
* @since 11.1
*/
public function getName()
{
if (empty($this->_name))
{
$class = get_class($this);
$pos = strpos($class, 'View');
if ($pos === false)
{
JError::raiseError(500, JText::_('JLIB_APPLICATION_ERROR_VIEW_GET_NAME'));
}
$tmp = strtolower(substr($class, ($pos + 4)));
// Remove the format from the end of the string.
$format = JFactory::getApplication()->input->get('format', 'html');
$this->_name = preg_replace('/(' . strtolower($format) . ')$/', '', $tmp);
}
return $this->_name;
}
}
@iPublicis
Copy link

How to apply this to Joomla 2.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment