2017-07-07 191 views
1

我正嘗試使用this指南向Magento CMS頁面編輯器添加自定義字段,但我無法獲取要在後端顯示的其他字段。嘗試將自定義字段添加到Magento頁面CMS

這裏是我所創建的文件:在/ app/etc/modules中

<config> 
    <modules> 
     <ddog_customcms> 
      <active>true</active> 
      <codePool>local</codePool> 
      <depends/> 
     </ddog_customcms> 
    </modules> 
</config> 

config.xml文件在/ app /代碼

ddog_customcms.xml /本地/ ddog/customcms/etc

<?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數據庫表

observer.php在/ app /代碼/本地/ ddog/customcms /型號/

<?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

看看這個答案:https://開頭的Magento .stackexchange.com/a/53094 – Rushikumar

+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,也將努力

+0

好景點!我已經將方法名稱修改爲cmsField,但編輯頁面時仍然看不到任何新字段。除清除緩存以顯示緩存外,還有什麼需要做的嗎? –

+0

您的班級名稱也是錯誤的 –

+0

代碼中沒有任何錯誤我嘗試了您的代碼並將其工作只是將觀察者的類名更改爲Ddog_Customcms_Model_Observer –

相關問題