English 中文(简体)
Magento: 从程序上更改部件配置
原标题:Magento: Programmatically change a widget s configuration

我要从部件代码 s 中更改并保存部件配置。 我在找类似的东西 :

class My_Module_Block_Widget
    extends Mage_Catalog_Block_Product_List
    implements Mage_Widget_Block_Interface
{
    // ...
    protected function _beforeToHtml()
    {
        // ...
        if(/* data needs to be changed */)
        {
            // assuming "widget_config_data" to be one of the widget s
            // parameters configured in the etc/widget.xml file of my module
            $this->setData("widget_config_data", "New Data");
            $this->save();
        }
        // ...
    }
    // ...
}

由于部件不是模型, 它们没有保存( ) 方法 。 因此如何保存已更改的部件数据?

最佳回答

s 将是一个棘手的问题, 并且可能更多涉及一个单一的堆叠溢问题。 这里有些背景可以启动您。 您要处理的类/ 对象是一个块类。 块用于生成 HTML 。 正如您已经指出的, 它们是无国籍的 。

块从部件实例模型对象获取数据 。

Mage::getModel( widget/widget_instance );
Mage_Widget_Model_Widget_Instance

这些对象的状态( 您试图更改的数据) 位于表格 < code>widget_ Instance

问题是, 块对象对部件实例对象一无所知 。 部件被插入到页面布局布局中, 带有存储在数据库中的特殊的布局控管( 是一个过度简化, 因为您可以写入 < a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<reference name="content">
    <block type="cms/widget_page_link" name="48fc761f38fa9838fcc3a3b498c47f72" template="cms/widget/link/link_block.phtml">
        <action method="setData">
            <name>anchor_text</name>
            <value>asdfasdfsad</value>
        </action>
        <action method="setData">
            <name>title</name>
            <value>asdfasdfasdfasd</value>
        </action>
        <action method="setData">
            <name>page_id</name>
            <value>2</value>
        </action>
    </block>
</reference>

中未提及部件实例 ID,这意味着您无法装入实例对象。

在理论上, 您可以尝试根据参数值装入部件实例, 因为这些 < 坚固> 存储在数据库中 。 但是, 它们会重新存储在 < code> widget_ paramater 列中, 是一个序列字符串 。 这意味着您不能使用 SQL 或模型文件员来查询它。 您必须先手动装入特定实例类型/ 主题/ 服务器的所有部件实例, 然后手动输入 < code> foreach < / code > 直至您找到正确的对象。 对于少量部件来说, 这可能具有性能, 但对于大量部件来说会很快变得不具有性能。 另外, 这也会被忽略到工作上, 因为( 虽然可能性不大) 您部件参数的值可能已经被其他布局更新代码更改 。

越好, (和更费时) 的方法是重写插入代码的部件, 使其在版式更新 XML 中包含一个页代号。 这将将例 id 传送到部件块代码, 允许您即时编辑一个部件实例对象并保存它。 您也可以在一个自定义类总是保存实例 ID 的部件中添加字段 。

祝你好运!

问题回答

暂无回答




相关问题
Javascript drop down menu widget

I have a menu consisting of an <ul> in a Web CMS. I want several menu items to have sub-items that are displayed in a dropdown list. These sub-items are <ul>s as well. This is basically ...

placing widget in listbox/dropdown in gwt

i am using gwt to build my web site. i would like to create a dropdown/listbox that contains no just text but also images, meaning that in the drop down there will be a what ever widget that ill ...

Share & Embed Widget design samples?

I am searching for some sample interface or design for creating a "Share & Embed Widget or Link" interface in my website. I found scribd.com s interface interesting http://www.scribd.com/doc/...

Marketshare of cross-platform widget libraries?

For a variety of reasons, we re in the market for a cross-platform widget library. We re in the somewhat rare situation of not being tied to a particular programming language at this stage, so we get ...

Dojo Tabs as Custom Widgets

I ve created a number of widgets that are loaded as tab panes in a tabcontainer. Everything seems to work well, except I m getting different results when using my custom widgets vs. creating ...

google chat web client

I am looking for a google chat client that I can embed in my website so visitors can chat with me directly. I haven t found any widgets like the google voice widget in which a visitor is connected ...

Hiding a QWidget on a QToolbar?

I have directly added some QWidgets to a QToolbar but simply going widget->setVisible(false) did not work. Can someone please give me an example of how to show and hide a widget that is on a QToolbar? ...

热门标签