尝试将自定义字段添加到Magento页面CMS

时间:2017-07-07 12:31:49

标签: php xml magento magento-1.9

我正在尝试使用this指南向Magento CMS页面编辑器添加自定义字段,但我无法在后端显示其他字段。

以下是我创建的文件:

/ app / etc / modules中的

ddog_customcms.xml

<config>
    <modules>
        <ddog_customcms>
            <active>true</active>
            <codePool>local</codePool>
            <depends/>
        </ddog_customcms>
    </modules>
</config>
/ app / code / local / ddog / customcms / etc中的

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <ddog_customcms>
            <version>1.0.0</version>
        </ddog_customcms>
    </modules>
    <global>
        <models>
            <ddog_customcms>
                <class>ddog_customcms_Model</class>
            </ddog_customcms>
        </models>
        <events>
            <adminhtml_cms_page_edit_tab_content_prepare_form>
                <observers>
                    <ddog_customcms_page_edit_tab_content>
                        <type>singleton</type>
                        <class>ddog_customcms_Model_Observer</class>
                        <method>cmsField</method>
                    </ddog_customcms_page_edit_tab_content>
                </observers>
            </adminhtml_cms_page_edit_tab_content_prepare_form>
        </events>
        <resources>
            <ddog_customcms_setup>
                <setup>
                    <module>ddog_customcms</module>
                </setup>
            </ddog_customcms_setup>
        </resources>
    </global>
</config>

将content_custom列添加到cms_page数据库表

/ app / code / local / ddog / customcms / Model / 中的observer.php

<?php

class ddog_customcms_observer
{
    public function addNewCmsField($observer)
    {
        //get CMS model with data
        $model = Mage::registry('cms_page');
        //get form instance
        $form = $observer->getForm();
        //create new custom fieldset 'ddog_customcms_content_fieldset'
        $fieldset = $form->addFieldset('ddog_customcms_content_fieldset', array('legend'=>Mage::helper('cms')->__('Custom'),'class'=>'fieldset-wide'));
        //add new field
        $fieldset->addField('content_custom', 'text', array(
            'name'      => 'content_custom',
            'label'     => Mage::helper('cms')->__('Content Custom'),
            'title'     => Mage::helper('cms')->__('Content Custom'),
            'disabled'  => false,
            //set field value
            'value'     => $model->getContentCustom()
        ));

    }
}

我已经清除了缓存但我无法让该字段出现在页面编辑器中的任何位置。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

这里是声明

<events>
     <adminhtml_cms_page_edit_tab_content_prepare_form>
         <observers>
             <ddog_customcms_page_edit_tab_content>
                 <type>singleton</type>
                 <class>ddog_customcms_Model_Observer</class>
                 <method>cmsField</method>
             </ddog_customcms_page_edit_tab_content>
         </observers>
     </adminhtml_cms_page_edit_tab_content_prepare_form>
</events>

您设置了方法名称cmsField但是在观察者中您编写了方法名称addNewCmsField,将其更改为cmsField并且它将起作用