为此,在/brands/adminhtml_brand/new/
我的自定义模块的管理面板中,当我想向数据库添加新条目时,我应该会看到一个页面。我正在关注本教程。我layout.xml
的设置正确。
BrandController.php
class Desbest_Brands_Adminhtml_BrandController extends Mage_Adminhtml_Controller_Action
public function editAction()
{
$id = $this->getRequest()->getParam('id', null);
$model = Mage::getModel('brands/example');
if ($id) {
$model->load((int) $id);
if ($model->getId()) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if ($data) {
$model->setData($data)->setId($id);
}
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('brands')->__('Example does not exist'));
$this->_redirect('*/*/');
}
}
Mage::register('example_data', $model);
$this->loadLayout();
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->renderLayout();
}
}
编辑.php
<?php
class Desbest_Brands_Block_Adminhtml_Example_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');
}
}
}
网格.php
<?php
class Desbest_Brands_Block_Adminhtml_Example_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('example_grid');
$this->setDefaultSort('id');
$this->setDefaultDir('desc');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('brands/example')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => Mage::helper('brands')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'id',
));
$this->addColumn('attributelabelid', array(
'header' => Mage::helper('brands')->__('Name'),
'align' =>'left',
'index' => 'name',
));
$this->addColumn('name', array(
'header' => Mage::helper('brands')->__('Description'),
'align' =>'left',