Magento 管理问题

标签 magento

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

Fatal error: Call to a member function setData() on a non-object in /Applications/MAMP/htdocs/theBookClub/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 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();
 }
}

如有任何帮助,我们将不胜感激!

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

}

最佳答案

这可能会解决您的问题:

在您的表单容器类中:

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

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

祝你好运!

关于Magento 管理问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10608203/

相关文章:

magento - 如何检查产品是否为简单产品

Magento 仪表板总销售价格仍未更新为 0.-

mysql - 列出过去 12 个月内未订购的 Magento 客户

php - Magento 2 URL 重写问题 : URL key already exists for specified store

magento - 如何在管理面板内制作可以 CRUD 自定义表的 Magento 模块?

php - Magento - 从 $item 获取产品选项

css - Magento 响应式设计 - 横向产品类别

Magento 1.7.0.2 启用 paypal 标准后订单未显示在我的帐户中

mysql - 如何使用观察者将新列添加到订单网格?

PHP fatal error : Uncaught exception 'CredisException' with message 'Lost connection to Redis server