[英]Trying to add a custom field to the Magento page CMS
I am attempting to add a custom field to the Magento CMS page editor using this guide, but I am not able to get the additional field to display in the backend. 我正在尝试使用此指南将自定义字段添加到Magento CMS页面编辑器,但是我无法获取其他字段以在后端显示。
Here are the files I have created: 这是我创建的文件:
ddog_customcms.xml in /app/etc/modules / app / etc / modules中的ddog_customcms.xml
<config>
<modules>
<ddog_customcms>
<active>true</active>
<codePool>local</codePool>
<depends/>
</ddog_customcms>
</modules>
</config>
config.xml in /app/code/local/ddog/customcms/etc / 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 column added to cms_page database table content_custom列已添加到cms_page数据库表
observer.php in /app/code/local/ddog/customcms/Model/ / 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()
));
}
}
I have cleared the cache but I can't get the field to appear anywhere in the page editor. 我已经清除了缓存,但是无法在页面编辑器中的任何位置显示该字段。 Can anybody help?
有人可以帮忙吗?
here in declaration 在这里声明
<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>
you set method name cmsField
but in observer you write method name addNewCmsField
change it to cmsField
and it will work 您设置了方法名称
cmsField
但是在观察器中您编写了方法名称addNewCmsField
将其更改为cmsField
,它将起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.