Magento管理员问题

时间:2012-05-15 20:16:24

标签: magento

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

  

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

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

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();
 }
}

感谢任何帮助!

NEW

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 个答案:

答案 0 :(得分: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

您可能需要调整类名,文件路径或两者,以使其正常工作。

祝你好运!

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

假设你的Adminhtml控制器不足 命名空间/模块名/控制器/ Adminhtml / BookshelfController.php

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

答案 3 :(得分:0)

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

所以试试:

  

$ this-> _blockGroup =' namespace_bookshelf&#39 ;;

     

$ this-> _controller =' adminhtml_bookshelf';