4

嗨,我正在为我的扩展创建我的第一个管理部分。我创建了一个链接到显示网格的页面的菜单。问题是当您单击以编辑记录时,它会显示此错误

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

在我的一生中,我在任何相关文件中都看不到任何参考

class Namespace_Bookshelf_Block_Adminhtml_Bookshelf_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
   public function __construct()
{
    parent::__construct();

    $this->_objectId = 'id';
    $this->_blockGroup = 'bookshelf';
    $this->_controller = 'bookshelf_admin';
    $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('bookshelf')->__('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('bookshelf')->__('Edit Example "%s"', $this->htmlEscape(Mage::registry('example_data')->getName()));
    } else {
        return Mage::helper('bookshelf')->__('New Example');
    }
}

还有这个

class Namespace_Bookshelf_Block_Adminhtml_Bookshelf_Grid extends                Mage_Adminhtml_Block_Widget_Grid {

public function __construct() {
    parent::__construct();
    $this->setId('bookshelf_grid');
    $this->setDefaultSort('bookshelf_id');
    $this->setDefaultDir('desc');
    $this->setSaveParametersInSession(true);
}

protected function _prepareCollection() {
    $collection = Mage::getModel('bookshelf/bookshelf')->getCollection();
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

protected function _prepareColumns() {
    $this->addColumn('bookshelf_id', array(
        'header' => Mage::helper('bookshelf')->__('ID'),
        'align' => 'right',
        'width' => '50px',
        'index' => 'bookshelf_id',
    ));

    $this->addColumn('customer_id', array(
        'header' => Mage::helper('bookshelf')->__('Name'),
        'align' => 'left',
        'index' => 'customer_id',
    ));

    $this->addColumn('bookshelf_name', array(
        'header' => Mage::helper('bookshelf')->__('Name'),
        'align' => 'left',
        'index' => 'bookshelf_name',
    ));



    return parent::_prepareColumns();
}





public function getRowUrl($row) {
    return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}

}

还有这个

class Newdaymedia_Bookshelf_Block_Adminhtml_Bookshelf extends
Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'bookshelf_admin';
$this->_blockGroup = 'bookshelf';
$this->_headerText = Mage::helper('bookshelf')->__('Item Manager');
$this->_addButtonLabel = Mage::helper('bookshelf')->__('Add Item');
parent::__construct();
}

protected function _prepareLayout()
 {
   $this->setChild( 'grid',
       $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
       $this->_controller . '.grid')->setSaveParametersInSession(true) );
   return parent::_prepareLayout();
 }
}

任何帮助将不胜感激!

新的

class Namespace_Bookshelf_Block_Adminhtml_Bookshelf_Edit_Form extends     Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
    if (Mage::getSingleton('adminhtml/session')->getExampleData())
    {
        $data = Mage::getSingleton('adminhtml/session')->getExamplelData();
        Mage::getSingleton('adminhtml/session')->getExampleData(null);
    }
    elseif (Mage::registry('example_data'))
    {
        $data = Mage::registry('example_data')->getData();
    }
    else
    {
        $data = array();
    }
    Mage::log("this is the form class");
    $form = new Varien_Data_Form(array(
            'id' => 'edit_form',
            'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
            'method' => 'post',
            'enctype' => 'multipart/form-data',
    ));

    $form->setUseContainer(true);

    $this->setForm($form);

    $fieldset = $form->addFieldset('example_form', array(
         'legend' =>Mage::helper('bookshelf')->__('Example Information')
    ));

    $fieldset->addField('name', 'text', array(
         'label'     => Mage::helper('bookshelf')->__('Name'),
         'class'     => 'required-entry',
         'required'  => true,
         'name'      => 'name',
         'note'     => Mage::helper('awesome')->__('The name of the example.'),
    ));

    $fieldset->addField('description', 'text', array(
         'label'     => Mage::helper('bookshelf')->__('Description'),
         'class'     => 'required-entry',
         'required'  => true,
         'name'      => 'description',
    ));

    $fieldset->addField('other', 'text', array(
         'label'     => Mage::helper('bookshelf')->__('Other'),
         'class'     => 'required-entry',
         'required'  => true,
         'name'      => 'other',
    ));

    $form->setValues($data);

    return parent::_prepareForm();
}

}

4

4 回答 4

7

这可能会解决您的问题:

在您的表单容器类中:

Namespace_Bookshelf_Block_Adminhtml_Bookshelf_Edit 
extends Mage_Adminhtml_Block_Widget_Form_Container

如果添加这些测试行,您将看到 Magento 正在尝试加载哪个 Form 类

$form_block = $this->_blockGroup . '/' . 
              $this->_controller . '_' . 
              $this->_mode . 
              '_form';
echo $form_block;

为了与您的代码(上图)一起使用,您的班级:

Namespace_Bookshelf_Block_Adminhtml_Bookshelf_Edit_Form

应该回显一个测试值:

bookshelf/adminhtml_bookshelf_edit_form

并且应该在以下文件路径中:

app/code/local/Namespace/Bookshelf/Block/Adminhtml/Bookshelf/Edit/Form.php

您可能必须调整类名或文件路径,或两者兼而有之,才能使其正常工作。

祝你好运!

于 2013-09-03T08:33:08.007 回答
1

您需要为您的模块创建一个助手(即使它什么都不做)。在模块的帮助器目录中创建一个名为 Data.php 的文件,并在其中创建一个名为 Namespace_Module_Helper_Data 的类,该类扩展 Mage_Core_Helper_Abstract。

我认为这应该有助于解决问题。

于 2012-05-15T21:30:11.890 回答
0

假设您的 Adminhtml 控制器位于 Namespace/ModuleName/controllers/Adminhtml/BookshelfController.php

试试 $this->_controller = 'adminhtml_bookshelf'; 在您的表单容器上。

于 2013-05-09T14:05:24.240 回答
0

重要的是要澄清 $this->_controller 不是实际的控制器名称,而是块类名称,而 $this->_blockGroup 实际上是模块名称。

所以试试:

$this->_blockGroup = 'namespace_bookshelf';

$this->_controller = 'adminhtml_bookshelf';

于 2016-01-20T14:29:00.143 回答