2010-10-04 62 views

回答

6

在你將選擇的物品的後端,物品的ID將被存儲在部件PARAMS(​​3210)或自定義組件PARAMS表的數據庫。

在您的自定義組件

  1. 商店文章編號,以可變
  2. 查詢數據庫#__content表文章編號
  3. 顯示文章

例如

// 
// Function for your model 
// 
/** 
* 
* @return object 
* 
* Object will have following structure 
* 
* Field   Type  
* ----------------------------------   
* id    "int(11) unsigned" 
* title   varchar(255) 
* alias   varchar(255) 
* title_alias varchar(255) 
* introtext  mediumtext 
* fulltext   mediumtext 
* state   tinyint(3) 
* sectionid  "int(11) unsigned" 
* mask    "int(11) unsigned" 
* catid   "int(11) unsigned" 
* created   datetime 
* created_by  "int(11) unsigned" 
* created_by_alias varchar(255) 
* modified   datetime 
* modified_by "int(11) unsigned" 
* checked_out "int(11) unsigned" 
* checked_out_time datetime 
* publish_up  datetime 
* publish_down datetime 
* images   text 
* urls    text 
* attribs   text 
* version   "int(11) unsigned" 
* parentid   "int(11) unsigned" 
* ordering   int(11) 
* metakey   text 
* metadesc   text 
* access   "int(11) unsigned" 
* hits    "int(11) unsigned" 
* metadata   text 
*/ 
public function getMyArticle() { 

     // Get Component parameters (config.xml) 
     $params = JComponentHelper::getParams('com_mycomponent'); 

     // Get Specific parameter 
     $myArticleId = (int) $params->get('articleId', 0); 

     // Make sure parameter is set and is greater than zero 
     if ($myArticleId > 0) { 

      // Build Query 
      $query = "SELECT * FROM #__content WHERE id = $myArticleId"; 

      // Load query into an object 
      $db = JFactory::getDBO(); 
      $db->setQuery($query); 
      return $db->loadObject(); 
     } 

     // 
     return null; 
    } 

要在後端彈出窗口中選擇,編輯組件的​​3210

添加addpath<params>元素

<!-- Add the path to content elements --> 
<params addpath="/administrator/components/com_content/elements"> 
    <!-- Add Select Article param --> 
    <param name="articleId" type="article" default="0" label="Select Article" description="" /> 

您還需要config按鈕添加到工具欄上的組件默認視圖

// Add this code in the display() method of the view 
// @todo change com_mycomponent to your component's name 
JToolBarHelper::preferences('com_mycomponent') 
+0

謝謝! :)它正在工作,但進一步如何使彈出選擇表單在後端選擇文章? – miojamo 2010-10-04 12:52:27

+0

請參閱答案的第二部分 – Alex 2010-10-04 13:39:02

+0

這是一個很好的例子,但我希望在相同的設置頁面上使用它,而不是使用參數和首選項。只需簡單的按鈕 – miojamo 2010-10-05 07:47:48