簡體   English   中英

Magento自定義管理模塊所見即所得集成

[英]Magento custom admin module wysiwyg integration

我已經根據此處的教程創建了一個管理模塊。 我試圖根據此處找到的信息將兩個表單輸入更改為所見即所得編輯器。 但是,每當我加載編輯頁面時,都會Call to a member function setCanLoadTinyMce() on a non-object出現錯誤Call to a member function setCanLoadTinyMce() on a non-object $this->getLayout()->getBlock('head') var_dumps為false。

命名空間/幻燈片/塊/ Adminhtml /幻燈片/Edit.php如下所示

class Namespace_Slides_Block_Adminhtml_Slide_Edit
    extends Mage_Adminhtml_Block_Widget_Form_Container
{
    protected function _prepareLayout() 
    {
        parent::_prepareLayout();
        if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
            $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
        }
    }

    protected function _construct() 
    {
        //... Construction stuff
    }
}

命名空間/幻燈片/塊/ Adminhtml /幻燈片/Edit/Form.php

class Cfw_Slides_Block_Adminhtml_Slide_Edit_Form
    extends Mage_Adminhtml_Block_Widget_Form
{

    protected function _prepareForm() 
    {
       //...Do some things first, like create the fieldset..


        //Add the editable fields
        $this->_addFieldsToFieldset($fieldset, array(
            'foreground_image' => array(
                'label' => $this->__('Foreground Image'),
                'input' => 'image',
                'required' => false,
            ),
            'background_image' => array(
                'label' => $this->__('Background Image'),
                'input' => 'editor',
                'required' => true,
                'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
                'wysiwyg' => true,
            ),
            'description' => array(
                'label' => $this->__('Text Overlay'),
                'input' => 'editor',
                'required' => false,
                'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
                'wysiwyg' => true,
            )
        )); 
        return $this;
    }


    protected function _addFieldsToFieldset(
        Varien_Data_Form_ElementFieldset $fieldset, $fields)
    {
        $requestData = new Varien_Object($this->getRequest()->getPost('slideData'));
        foreach ($fields as $name => $_data) {
            if ($requestValue = $requestData->getData($name)) {
                $_data['value'] = $requestValue;
            }

            //Wrap all fields with slideData group
            $_data['name'] = "slideData[$name]";

            //Generally, label and title are always the same
            $_data['title'] = $_data['label'];

            //If no new value exists, use the existing slide data.
            if (!array_key_exists('value', $_data)) {
                $_data['value'] = $this->_getSlide()->getData($name);
            }

            //Finally, call vanilla funcctionality to add field.
            $fieldset->addField($name, $_data['input'], $_data);
        }
        return $this;
    }


}

我不確定您是否需要它,但是這也是我的文件結構

Namespace
-Slides
--Block
---Adminhtml
----Slide
-----Edit
------Form.php
-----Edit.php
-----Grid.php
----Slide.php
--controllers
---Adminhtml
----SlideConroller.php
--etc
---config.xml
--Helper
---Data.php
--Model
---Resource
----Slide
-----Collection.php
----Slide.php
---Slide.php
--sql
---namespace_slides_setup
----install-0.0.1.php

問題是Magento無法找到您的head

而不是使用:

$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);

嘗試這樣稱呼它:

Mage::app()->getLayout()->getBlock('head')->setCanLoadTinyMce(true);

如果那不起作用,那是另一個問題,但是問題仍然是Magento找不到head塊。

我想您不再需要解決方案,但是我使用與您相同的教程遇到了同樣的問題。

通過_prepareLayout()函數,Edit.php和Form.php中無法使用“ head”塊(以及setCanLoadTinyMce())。

'head'塊在控制器中(在您的情況下為SlideController.php)在editAction()函數的$ this-> loadLayout()和$ this-> renderLayout之間可用。

SlideController.php更改

$this->loadLayout()
        ->_addContent($brandBlock)
        ->renderLayout();

$this->loadLayout() ;               
$this->_addContent($brandBlock);                                        
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
$this->renderLayout();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM