我们如何在magento自定义模块中添加wysiwyg编辑器?
答案 0 :(得分:3)
1)打开文件Block_Adminhtml__Edit_Tab_Form
编辑字段
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('developerpage_form', array('legend'=>Mage::helper('developerpage')->__('Item information')));
/ *在此添加以下代码* /
$configSettings = Mage::getSingleton('cms/wysiwyg_config')->getConfig();
$configSettings['files_browser_window_url'] = $this->getBaseUrl().'admin/cms_wysiwyg_images/index/';
Mage::getSingleton('cms/wysiwyg_config')->setConfig($configSettings);
/ *为fieldset添加如下* /
$fieldset->addField('detail', 'editor', array(
'name' => 'detail',
'label' => Mage::helper('developerpage')->__('Content'),
'title' => Mage::helper('developerpage')->__('Content'),
'style' => 'width:700px; height:500px;',
'config' => $configSettings,
'required' => true,
));
2)打开controllers / adminhtml / testcustomercontroller.php找到editAction
在editAction中找到$ this-> loadLayout(); 并粘贴以下代码;
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
3)打开desing / adminhtml / default / default / yourmodule xml文件并在xml下面添加
/* this is my module change with yours */
<developerpage_adminhtml_developerpage_edit>
<update handle="editor" />
</developerpage_adminhtml_developerpage_edit>
NOTE: Dont give field name or id name "content" of editor field nor in Database
Call editor content like below other wise directive would't convert
$_cmsHelper = Mage::helper('cms');
$_process = $_cmsHelper->getBlockTemplateProcessor();
echo $_process->filter(Here your database content);
现在可以插入图像。 :)