2013-09-12 02:17


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( but still remain clueless. Please, any help would be greatly appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douke1942 douke1942 8年前

    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);
    点赞 评论 复制链接分享
  • dthp96899 dthp96899 8年前

    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!


    点赞 评论 复制链接分享
  • doumiao0498 doumiao0498 8年前

    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.

    点赞 评论 复制链接分享