magento - 预配置的 Magento 小部件

标签 magento

是否有用户界面或程序系统来利用 Magento 的 CMS 页面渲染中的“预配置小部件”功能?

向 CMS 页面添加小部件时,呈现该小部件的代码位于模板指令处理类中。这段代码

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

加载 Widget 的参数时,有以下代码
// 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 '';
}

这段代码似乎解析了一个 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 table 。
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 Inc. 工作)知道这是否是受支持的功能,或者它是否是已被放弃但出于向后兼容性原因而保留的功能的开始?

最佳答案

这个答案有点离题,但我不确定它是否能满足您的需求。我发现您可以在管理 CMS>Widgets 部分中创建小部件实例,然后通过以下代码呈现它们:

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

请注意,块是按标题(而不是任意 ID)加载的,并且会传递小部件参数以供块渲染。

关于magento - 预配置的 Magento 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4854452/

相关文章:

Magento - 将邮政编码/邮政编码添加到 Magento 1.6.2 中的订单网格中

magento - 重写 Magento session 的最后一个 URL

php - 在 Magento 之外但在同一域中获取购物车内容

php - 为 magento 创建产品矩阵

apache - 访问 Magento 安装时出现 302 响应

Magento:从产品集合中获取所有产品而忽略设置的限制?

css - Magento - MegaMenu 问题,背景不向左浮动

php - 仅在主页上显示在 Magento 中的 Logo

css - 仅在一种语言的标题中添加自定义 CSS 文件

magento - 在 CentOS6 中安装 Redis 服务器,如何?