Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is JHtml::_?

Tags:

joomla

following is the code i am trying to understand of joomla MVC compenet development

protected function getOptions() 
    {
            $db = JFactory::getDBO();
            $query = $db->getQuery(true);
            $query->select('id,greeting');
            $query->from('#__helloworld');
            $db->setQuery((string)$query);
            $messages = $db->loadObjectList();
            $options = array();
            if ($messages)
            {
                    foreach($messages as $message) 
                    {
                            $options[] = JHtml::_('select.option', $message->id, $message->greeting);
                    }
            }
            $options = array_merge(parent::getOptions(), $options);
            return $options;
    }

i am unable to understand following statement

JHtml::_('select.option', $message->id, $message->greeting);

and what is the basic purpose of JHTML class of joomla

like image 798
arslan Avatar asked Sep 20 '13 05:09

arslan


2 Answers

JHTML is indeed a class of Joomla, used to print various HTML, like inputs, images, links etc. Here is the documentation:

http://api.joomla.org/Joomla-Platform/HTML/JHtml.html

UPDATE: more recent documentation http://api.joomla.org/cms-3/classes/JHtml.html

The underscore ( _ ) function calls other sub-classes, like

http://api.joomla.org/Joomla-Platform/HTML/JHtmlSelect.html

UPDATE: more recent documentation http://api.joomla.org/cms-3/classes/JHtmlSelect.html

UPDATE: method "_" documentation http://api.joomla.org/cms-3/classes/JHtml.html#method__

and the part after the dot ( . ) is the function called. In this case:

http://api.joomla.org/Joomla-Platform/HTML/JHtmlSelect.html#option

like image 73
mavrosxristoforos Avatar answered Oct 16 '22 09:10

mavrosxristoforos


i was reading a book about Joomla called JOOMLA PROGRAMMING, so i discovered what's the function of the method _(underscore) from class JHml, he say it's a way to call the methods from JHML subclasses as JHTML content, bootstrap, string, so as exp: variable = JHtml::_(string.truncate) ?> is like you type variable = JHtmlString->truncate(); ?> so i understand this way.

like image 25
Diego Raian Avatar answered Oct 16 '22 10:10

Diego Raian