10

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

arslan
  • 565
  • 1
  • 7
  • 25

2 Answers2

9

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

IberoMedia
  • 2,226
  • 7
  • 36
  • 61
mavrosxristoforos
  • 3,573
  • 2
  • 25
  • 40
  • i had gone through these links already, but before your reply i was unable to link things togethor. thanks for your reply but dont u you think joomla documentation is lacking details? if yes where to get extra details and examples of usgae of joomla platform. – arslan Sep 20 '13 at 05:46
  • Joomla docs do admittedly lack detail in some areas, but mainly with the more intricate classes that aren't so popular. A lot of example are forms on the Joomla Forum and Stackoverflow. – Lodder Sep 20 '13 at 05:50
  • 8
    Joomla has the worse documentation I have ever tried. Moreover, they are rushing into new versions, changing APIs without saying anything but "we removed this function". I have been struggling with this for years. In fact, I am a Joomla extension developer, and this is the most usual problem. To learn how things work, you have to read code by others. Start by knowing the Joomla components and see how they solved certain issues. – mavrosxristoforos Sep 20 '13 at 05:51
  • And the example component for Joomla 3 is just a demonstration of how to print "Ola" (which means "Hello" in Brazilian, since the developer is Brazilian). The rest, you have to find it yourself. – mavrosxristoforos Sep 20 '13 at 05:53
  • `Joomla has the worse documentation I have ever tried` << if you feel this bad about them, you could always contribute to make them better. New versions are not being rushed in mo opinion. Long term releases are released every 2 years with short term releases inbetween...[see here](http://community.joomla.org/blogs/leadership/1711-its-official-joomla-cms-to-add-32-release.html). The example component is simply there as an example, there is a lot of documentation on how to build a component for 2.5 and 3.x – Lodder Sep 20 '13 at 06:58
  • Do bare in mind that Joomla is not developed by a team and thus does not have specific people writing documentation. The community are the developers so the docs rely on all of us. – Lodder Sep 20 '13 at 07:06
  • I agree with you. Although, that doesn't change the fact that there is an inconsistency between suggested things for various versions of Joomla. I deeply support Joomla by developing for it, serving free extensions for 5 years now, some of which are included in commercial templates. Joomla is a great CMS, but that doesn't change the fact that it would have tons of incoming interested developers if the documentation was written on development time. And I'm sure you can think of dozens of other projects that are built by teams and offer great documentation, at least for a starter. – mavrosxristoforos Sep 20 '13 at 07:20
  • 4
    @Lodder, I understand and agree with some of what you write about the documentation. However, for people like me, who are learning as we go, even if we wanted to contribute to the documentation, the logic policy from one release to the next changes dramatically, Joomla developers are very ambitious, this is good albeit this makes it difficult for the non-core developer to keep up with. If high thinkers are busy developing, and enthusiastic learners are catching up with the curve, which is slow due to lack of documentation, who will contribute to systematized easy to maintain docs? – IberoMedia Dec 13 '13 at 08:52
  • 2
    last thing, I agree w/ mavrosxristoforos. We can develop a whole language, one that does terrific things, but if few people understand it? I LOVE joomla, but as intimidating and difficult as this would be, whoever leads this CMS MUST establish a systematized way, policies and rules, of how changes get documented, and then the implementation of easy intuitive ways to make docs easy for the consumer to understand and access it. When I look at all of the bookmarks I have for the various patchy docs of Joomla API, CMS, framework, etc docs I feel tremendous anxiety. Tremendous disincentive – IberoMedia Dec 13 '13 at 08:58
  • 3
    @IberoMedia - The's thew problem though, Joomla isn't particularly lead by a person or group of people. It has a PLT which are the people who basically make decisions about Joomla such as what goes into it and what comes out etc, but the development of Joomla and even the documentation is entirely community based. I do believe however that if a feature gets added into Joomla, then the people or people who have commited it should also write documentation for it. Doing this will make life much easier for other developer, especially for those who are new to Joomla. – Lodder Dec 13 '13 at 09:18
  • 1
    So overall, in some aspects I agree with you but it's up to the community to write documentation. And with all the classes and API code it contains, it would take a very long time to write docs for everything. I do feel strongly about those who commit new features should write documentation for it so I'm actually going to recommend this idea forwarded to the PLT and hopefully it will get applied :) – Lodder Dec 13 '13 at 09:21
  • I think we all agree. And there is another problem: I want to contribute in the documentation, but I am very unsure about what to write and where. And by that I mean that I don't want to write something that is wrong or misleading for a feature, because you can never be sure if you haven't made the thing... Let's just hope your suggestion will get the attention it needs. – mavrosxristoforos Dec 13 '13 at 13:31
  • Hopefully a StackExchange for Joomla will be able to help when the documentation is lacking http://area51.stackexchange.com/proposals/58842/joomla – TryHarder Feb 08 '14 at 14:37
1

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.