2010-01-29

Joomla 筆記 (個人紀錄)

// 取得目前所選用的 Template 路徑
$app =& JFactory::getApplication();
$templateDir = JURI::base() . 'templates/' . $app->getTemplate();

// Joomla Document Object
$doc =& JFactory::getDocument();

// 引用 Css File
$doc->addStyleSheet($templateDir . "/css/mycssfile.css");

// 引用 JavaScript File
$doc->addScript($templateDir . "/js/myJavaScript.js");

備註 : 可以使用 CDN 的方式來引用 JavaScript & Css File.
$templateDir 是目前使用中的樣板路徑


// 引用 Joomla DBO 物件
$db =& JFactory::getDBO();

// 查詢 Content Table 資料表
$stmt = "SELECT * FROM " . $db->getPrefix() . "content";
$db->setQuery($stmt, 0);

// 顯示查詢內容
if ($rows = $db->loadObjectList()) {
  foreach ($rows as $row) {
    printf("%s", $row->title);
    printf("%s", $row->alias);
    printf("%s", $row->introtext);
  }
}


由於 Joomla 預設是採用 mootools, 若你想使用其他 JavaScript 套件,
可以透過下面的程式碼來移除 mootools
// remove mootools.js and caption.js
$headerstuff = $this->getHeadData();
reset($headerstuff['scripts']);
foreach($headerstuff['scripts'] as $key=>$value){
  unset($headerstuff['scripts'][$key]);
}
$this->setHeadData($headerstuff);





沒有留言:

張貼留言