Php Magento自定义管理模块所见即所得集成

Php Magento自定义管理模块所见即所得集成,php,magento,magento-1.9,Php,Magento,Magento 1.9,我根据教程创建了一个管理模块。我正试图根据找到的信息将两个表单输入更改为wysiwyg编辑器。但是,每当我加载编辑页面时,就会收到对非对象上的成员函数setCanLoadTinyMce()的错误调用$this->getLayout()->getBlock('head')var\u转储为false Namespace/Slides/Block/Adminhtml/Slide/Edit.php如下所示 class Namespace_Slides_Block_Adminhtml_Slide_Edit

我根据教程创建了一个管理模块。我正试图根据找到的信息将两个表单输入更改为wysiwyg编辑器。但是,每当我加载编辑页面时,就会收到对非对象上的成员函数setCanLoadTinyMce()的错误调用
$this->getLayout()->getBlock('head')
var\u转储为false

Namespace/Slides/Block/Adminhtml/Slide/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
    }
}
名称空间/Slides/Block/Adminhtml/Slide/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找不到您的

而不是使用:

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

试着这样称呼它:

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


如果这不起作用,则是另一个问题,但问题仍然是Magento找不到

我想您不再需要解决这个问题,但我在使用与您相同的教程时遇到了相同的问题

通过_prepareLayout()函数,Edit.php和Form.php中的'head'块(以及setCanLoadTinyMce())不可用

“head”块在控制器中可用(在您的例子中是SlideController.php),位于editAction()函数中的$this->loadLayout()和$this->renderLayout之间

SlideController.php中
change

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


我试过了,但结果是一样的。我能做些什么来阻止它接近头部吗?我不确定它是否相关,但我也得到了在244行的/app/www/sites/cfw/app/code/core/Mage/core/functions.php中找不到的
Class'Mage',但只是指向一些错误打印的代码。这很奇怪,因为你在
if
条件中调用了
Mage::getSingleton
,所以我们知道它以前见过
Mage
。一些不太可能但可能是问题的事情:对于未找到的
图像
,您正在调用
父对象::\u construct()Edit.php
中的
\uu construct()
函数中的code>?这是不太可能的,但在学习这些教程时,他们通常会忽略
否我没有包括
父项::_construct()
。我现在添加了它,虽然结果是一样的。在提供代码时,我故意删除了所有php标记。我从教程中键入了代码,而不是复制和粘贴,因为我觉得我实际上可以通过这种方式来学习,而Sublime具有正确的语法突出显示,所以我认为这不是php标记。如果有帮助的话,我已经把剩下的代码放进了。
$this->loadLayout() ;               
$this->_addContent($brandBlock);                                        
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
$this->renderLayout();