全部来自parent::__construct();
Fatal error: Call to a member function setData() on a non-object in /home/desbest/public_html/clients/magentofull/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 129
<?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');
}
}
}
最佳答案
假设您正在处理 Magento 的纯净版本,请查看第 129 行
127: public function getFormHtml()
128: {
129: $this->getChild('form')->setData('action', $this->getSaveUrl());
130: return $this->getChildHtml('form');
131: }
您可以看到尝试获取名为 form 的子 block 无法返回对象。最有可能的是,这是因为在准备布局方法中,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'
不是一个有效的 block 类。在不知道你想做什么的情况下,我建议
public function __construct()
{
$this->_objectId = 'id';
$this->_blockGroup = 'brands';
$this->_controller = 'adminhtml_example';
$this->_mode = 'edit';
parent::__construct();
并确保您有别名的 block 类
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
{
//...
}
关于magento - 父级::__construct();函数导致问题,因为 setData() 表示没有对象,对于一个简单的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12079127/