jhtml :: script不再适用于joomla 3.7

时间:2017-09-16 21:20:50

标签: javascript joomla

以下代码在升级到3.7之前用于工作,但是行" JHtml :: script(' com_members / site.js',array(),true);"不再加载site.js

class MembersViewMembersELso extends JViewLegacy
{
        // Overwriting JView display method
        function display($tpl = null) 
        {
                // Get data from the model
                $state = $this->get('State');
                $items = $this->get('Items');
                $pagination = $this->get('Pagination');
                // Check for errors.
                if (count($errors = $this->get('Errors'))) 
                {
                        JError::raiseError(500, implode('<br />', $errors));
                        return false;
                }
                // Assign data to the view
                $this->state = $state;
                $this->items = $items;
                $this->pagination = $pagination;  
                // get the stylesheet (with automatic lookup, possible template overrides, etc.)
                JHtml::stylesheet('com_members/site.stylesheet.css', array(), true);
                // insert js code for onsubmit
                JHtml::script('com_members/site.js', array(), true);
                // Display the view
                parent::display($tpl);
        }
}

1 个答案:

答案 0 :(得分:0)

如果您只想包含一个JavaScript / CSS文件,则

JHtml::ScriptJHtml::Stylesheet不是理想的方法。这些方法中使用了大量不必要的开销,它们都使用高度复杂的includeRelativeFiles方法(您可以在libraries/cms/html/html.php中找到所有3种方法)。

包含文件的更简洁的方法是直接执行以下操作(当然,您需要删除上面代码中的JHtml::ScriptJHtml::Stylesheet):

$objDocument = JFactory::getDocument();
$objDocument->addStyleSheet(JUri::base() .'com_members/site.stylesheet.css');
$objDocument->addScript(JUri::base() .'com_members/site.js');