2017-09-16 46 views
0

下面的代碼在我升級到3.7之前工作,但行「JHtml :: script('com_members/site.js',array(),true);」不再加載site.jsjhtml :: script不再適用於joomla 3.7

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

JHtml::ScriptJHtml::Stylesheet不能使用,如果你只是想包括一個的JavaScript/CSS文件的理想方法。在這些方法中有很多不必要的開銷,它們都使用高度複雜的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'); 
+0

三江源。我會用你的建議,但是你有什麼想法,爲什麼在Joomla 3.7下JHtml :: Script語句突然失效了? –