Back to AbstractView class

Method getName

public string
getName
()
Method to get the view name
Returns
  • string The name of the model
Since
  • 3.0
-
  • \Exception
Class: AbstractView
Project: Joomla

Method getName - Source code

/**
 * Method to get the view name
 *
 * The model 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 model
 *
 * @since   3.0
 * @throws  \Exception
 */
public function getName()
{
    if (empty($this->_name)) {
        $reflection = new \ReflectionClass($this);
        if ($viewNamespace = $reflection->getNamespaceName()) {
            $pos = strrpos($viewNamespace, '\\');
            if ($pos !== false) {
                $this->_name = strtolower(substr($viewNamespace, $pos + 1));
            }
        } else {
            $className = \get_class($this);
            $viewPos = strpos($className, 'View');
            if ($viewPos != false) {
                $this->_name = strtolower(substr($className, $viewPos + 4));
            }
        }
        if (empty($this->_name)) {
            throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_GET_NAME', __METHOD__), 500);
        }
    }
    return $this->_name;
}