嗨,我正在为我的扩展创建我的第一个管理部分。我创建了一个链接到显示网格的页面的菜单。问题是当您单击以编辑记录时,它会显示此错误
致命错误:在第 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();
}
}