6

这一切都来自parent::__construct();

致命错误:在第 129 行的 /home/desbest/public_html/clients/magentofull/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php 中的非对象上调用成员函数 setData()

<?php 
class Desbest_Brands_Block_Adminhtml_Brand_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();

        $this->_objectId = 'id';
        $this->_blockGroup = 'brands';
        $this->_controller = 'adminhtml_example';
        $this->_mode = 'edit';

        $this->_addButton('save_and_continue', array(
                  'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
                  'onclick' => 'saveAndContinueEdit()',
                  'class' => 'save',
        ), -100);
        $this->_updateButton('save', 'label', Mage::helper('brands')->__('Save Example'));

        $this->_formScripts[] = "
            function toggleEditor() {
                if (tinyMCE.getInstanceById('form_content') == null) {
                    tinyMCE.execCommand('mceAddControl', false, 'edit_form');
                } else {
                    tinyMCE.execCommand('mceRemoveControl', false, 'edit_form');
                }
            }

            function saveAndContinueEdit(){
                editForm.submit($('edit_form').action+'back/edit/');
            }
        ";
    }

    public function getHeaderText()
    {
        if (Mage::registry('example_data') && Mage::registry('example_data')->getId())
        {
            return Mage::helper('brands')->__('Edit Example "%s"', $this->htmlEscape(Mage::registry('example_data')->getName()));
        } else {
            return Mage::helper('brands')->__('New Example');
        }
    }

}
4

2 回答 2

20

假设您正在处理一个纯粹的 Magento 版本,请查看第 129 行

127:    public function getFormHtml()
128:    {
129:        $this->getChild('form')->setData('action', $this->getSaveUrl());
130:        return $this->getChildHtml('form');
131:    }

您可以看到尝试获取名为 form 的子块的尝试未能返回对象。很可能,这是因为在准备布局方法中,Magento 未能实例化表单

protected function _prepareLayout()
{
    if ($this->_blockGroup && $this->_controller && $this->_mode) {
        $this->setChild('form', $this->getLayout()->createBlock($this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'));
    }
    return parent::_prepareLayout();
}

要么是因为您的班级没有设置以下变量之一

$this->_blockGroup
$this->_controller
$this->_mode

或字符串生成的类别名

$this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'

不是有效的块类。在不知道您要做什么的情况下,我建议

public function __construct()
{
    $this->_objectId = 'id';
    $this->_blockGroup = 'brands';
    $this->_controller = 'adminhtml_example';
    $this->_mode = 'edit';    
    parent::__construct();

并确保您有别名的块类

brands/adminhtml_example_edit_form
//from
//$this->_blockGroup . '/' . $this->_controller . '_' . $this->_mode . '_form'

这很可能是一个名为

class Desbest_Brands_Block_Adminhtml_Example_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    //...
}
于 2012-08-22T18:52:25.113 回答
1

您也有可能Desbest_Brands_Block_Adminhtml_Brand_Edit.php不在相应的文件夹Desbest/Brands/Block/Adminhtml/Brand/Edit中。

于 2015-11-27T10:08:06.680 回答