shenkwen
shenkwen

Reputation: 3880

What does double colons and underscore mean in Joomla?

I am learning basic PHP, trying to read and get some basic understanding of JOOMLA core files, whereas I come across a lot of operators like "::_", which I don't understand.

I did some google research and there are a lot of explanations regarding double colons (::), but almost nothing on "::_", one of the files that contain this operator is joomla-site-root/mod_login/tmpl/default.php, and the line is

<form action="<?php echo JRoute::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="login-form">

So what does this mean? Is "JRoute::_('index.php', true, $params->get('usesecure'))" a function call of class JRoute? if yes, what function is it? I checked out the joomla API(http://api.joomla.org/Joomla-Platform/Application/JRouter.html) but still remain clueless. Please, any help would be greatly appreciated.

Upvotes: 1

Views: 448

Answers (3)

Craig
Craig

Reputation: 9330

The :: as mentioned is the scope resolution operator, it allows access to static, constant, and overridden properties. So, in Joomla's case and your question it's accessing a class static method called '_'.

The underscore '_' is actually the name of the method.

In Joomla you will find lots of classes implement underscore methods, e.g. the default text translation utility:

echo JText::_('COM_MYCOMPONENT_SORT_BTN_LABEL');  // This is the most commonly used one.

Only a few though still use static functions. JHTML is an example where [JHTML::_][2] acts like a class loader, loading helper file based on the first parameter passed in as the $key

echo JHtml::_('behavior.tooltip');
echo JHtml::_('behavior.formvalidation');
echo JHtml::_('sliders.panel', JText::_($fieldset->label), $fieldset->name);
echo JHtml::_('link', JHelp::createUrl('JHELP_GLOSSARY'), JText::_('COM_ADMIN_GLOSSARY'), array('target' => 'helpFrame'));

JLanguage is a Joomla class with an underscore method that you may see used around the place but unlike JRoute, [JText][4] or [JHTML][5] it's not called statically. e.g.

$lang = JLanguage::getInstance($toUser->getParam('admin_language', $default_language), $debug);
$lang->load('com_messages', JPATH_ADMINISTRATOR);
$subject = sprintf ($lang->_('COM_MESSAGES_NEW_MESSAGE_ARRIVED'), $sitename);

Upvotes: 4

Rob
Rob

Reputation: 12872

The double colon is called the scope resolution operator and is used for calling static class methods or properties. Underscore doesnt mean anything but _() is usually used for string translations.

Upvotes: 0

WTFranklin
WTFranklin

Reputation: 2568

the double colon is used with OOP (object oriented programming). If you're new to programming in general, objects are really useful with reusing code and definitely worth looking into once you're more comfortable with programming in general... that is if you aren't already experienced. Hope that helps!

-Frank

Upvotes: 0

Related Questions