以下代码在升级到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);
}
}
答案 0 :(得分:0)
JHtml::Script
和JHtml::Stylesheet
不是理想的方法。这些方法中使用了大量不必要的开销,它们都使用高度复杂的includeRelativeFiles
方法(您可以在libraries/cms/html/html.php
中找到所有3种方法)。
包含文件的更简洁的方法是直接执行以下操作(当然,您需要删除上面代码中的JHtml::Script
和JHtml::Stylesheet
):
$objDocument = JFactory::getDocument();
$objDocument->addStyleSheet(JUri::base() .'com_members/site.stylesheet.css');
$objDocument->addScript(JUri::base() .'com_members/site.js');