2011-01-31 55 views
4

是否有一個用戶界面或程序系統利用Magento的CMS頁面呈現的一部分「預配置的小工具」的功能?預配置Magento小部件

向CMS頁面添加小部件時,呈現該小部件的代碼位於模板指令處理類中。此代碼

File: app/code/core/Mage/Widget/Model/Template/Filter.php 
class Mage_Adminhtml_Cms_PageController extends Mage_Adminhtml_Controller_Action 
{ 
    ... 
} 

當裝載Widget的PARAMATERS,有下面的代碼位

// validate required parameter type or id 
if (!empty($params['type'])) { 
    $type = $params['type']; 
} elseif (!empty($params['id'])) { 
    $preconfigured = Mage::getResourceSingleton('widget/widget') 
     ->loadPreconfiguredWidget($params['id']); 

    $type = $preconfigured['type']; 
    $params = $preconfigured['parameters']; 

} else { 
    return ''; 
} 

此代碼出現解析一個widget指示標記爲一個id值

{{widget name="foobazbar" id=""}} 

,然後從小部件模型加載配置

public function loadPreconfiguredWidget($widgetId) 
{ 
    $read = $this->_getReadAdapter(); 
    $select = $read->select(); 
    $select->from($this->getMainTable()) 
     ->where($this->getIdFieldName() . ' = ?', $widgetId); 
    var_dump((string)$select); 
    $widget = $read->fetchRow($select); 
    if (is_array($widget)) { 
     if ($widget['parameters']) { 
      $widget['parameters'] = unserialize($widget['parameters']); 
     } 
     return $widget; 
    } 
    return false; 
} 

當我第一次遇到這個代碼時,我認爲它正在加載一個Widget實例模型。但是,事實並非如此。而是加載widget/widget類的數據,該數據對應於widget表。

mysql> describe widget; 
+------------+------------------+------+-----+---------+----------------+ 
| Field  | Type    | Null | Key | Default | Extra   | 
+------------+------------------+------+-----+---------+----------------+ 
| widget_id | int(10) unsigned | NO | PRI | NULL | auto_increment | 
| code  | varchar(255)  | NO | MUL | NULL |    | 
| type  | varchar(255)  | NO |  | NULL |    | 
| parameters | text    | YES |  | NULL |    | 
+------------+------------------+------+-----+---------+----------------+ 

是否有用於將數據添加到此表的UI或系統?有沒有人(從Magento公司工作)誰知道這是一個支持的功能,或者如果這是一個被放棄的東西的開始,但出於向後兼容的原因?

+0

當然,菜單中有「CMS>小工具」,但我對它們沒有經驗,也沒有使用您建議的語法在CMS頁面中工作。我試過`{{widget id =「$ num」}}`。從你提供的代碼示例中不明顯你甚至需要`name`參數。 – Nick 2011-01-31 20:56:43

回答

0

通過幾條評論和私人郵件,看起來這是Magento核心團隊的一項祕密功能,並且與實例窗口小部件無關。

2

這個答案有點偏離主題,但我不確定它是否可以滿足您的需要。我發現,您可以在管理CMS>小工具部分創建控件實例,然後通過下面的代碼使其:

$oWidget = Mage::getModel('widget/widget_instance')->load('HomepageTwitter','title'); 
$oWidgetBlock = Mage::app()->getLayout()->createBlock($oWidget->getType(), $oWidget->getTitle(), $oWidget->getWidgetParameters()); 
echo $oWidgetBlock->toHtml(); 

注意,塊是由標題(而不是任意的ID)加載,小部件參數被傳遞給Block進行渲染。