arslan
arslan

Reputation: 585

what is JHtml::_?

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

Upvotes: 10

Views: 11910

Answers (2)

Diego Raian
Diego Raian

Reputation: 29

I was reading a book about Joomla called JOOMLA PROGRAMMING, so I discovered what's the function of the method _(underscore) from class JHml.

It says it's a way to call the methods from JHML subclasses as JHTML content, bootstrap, string, so as an example:

<?php $this->variable = JHtml::_(string.truncate) ?>

is like you type:

<?php $this->variable = JHtmlString->truncate(); ?>

This is how I understand it.

Upvotes: 1

mavrosxristoforos
mavrosxristoforos

Reputation: 3643

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

Upvotes: 9

Related Questions