magento adminpanel表单中缺少保存和删除按钮,表格的位置是否保留?

时间:2015-08-27 12:10:52

标签: magento

我一直关注this来创建管理网格视图。网格工作正常但当我尝试加载表单来编辑或删除或保存我的条目时,我的表单容器中没有保存和删除按钮,请参阅此处https://www.dropbox.com/s/odk79gsvufpj9j9/Screenshot%20from%202015-08-28%2014%3A37%3A08.png?dl=0

这是我的Edit.php

class Best_Test_Block_Adminhtml_Test_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::_construct();
        $this->_objectId = 'id';
        $this->_blockGroup = 'test';
        $this->_controller = 'adminhtml_test';
        $this->_updatebutton('save', 'label', 'save user');
        $this->_updatebutton('delete', 'label', 'delete user');

    }
    public function getHeaderText()
    {
        if (Mage::registry('test_data')&&Mage::registry('test_data')->getId()) {
            return 'Edit user '.$this->htmlEscape(Mage::regisrty('test_data')->getTitle()).'<br/>';
        }else{
            return 'Add a user';
        }
    }
}

这是我在Adminhtml中的indexController.php

class Best_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
    protected function _initAction()
    {
        $this->loadLayout()->_setActiveMenu('test/set_time')->_addBreadcrumb('test Manager', 'test Manager');
        return $this;
    }
    public function indexAction()
    {
      $this->_initAction();
      $this->renderLayout();
    }
    public function editAction()
    {
        $testId = $this->getRequest()->getParam('id');
        $testModel = Mage::getModel('test/test')->load($testId);
        if ($testModel->getId() || $testId == 0) {
            Mage::register('test_data', $testModel);
            $this->loadLayout();
            $this->_setActiveMenu('test/set_time');
            $this->_addBreadcrumb('test Manager', 'test Manager');
            $this->_addBreadcrumb('Test Description', 'Test Description');
            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
            $this->_addContent($this->getLayout()->createBlock('test/adminhtml_test_edit'))->_addLeft($this->getLayout()->createBlock('test/adminhtml_test_edit_tabs'));
            $this->renderLayout();
        }else{
            Mage::getSingleton('adminhtml/session')->addError('Test does not exist!');
            $this->_redirect('*/*/');
        }
    }
    public function newAction()
    {
        $this->_forward('edit');
    }
    public function saveAction()
    {
        if ($this->getRequest()->getPost()) {
            try{
                $postData = $this->getRequest()->getPost();
                $testModel = Mage::getModel('test/test');
                if ($this->getRequest()->getParam('id') <= 0) {
                    $testModel->setCreatedTime(Mage::getSingleton('core/date')->gmtDate());
                    $testModel->addData($postData)->setUpdateTime(Mage::getSingleton('core/date')->gmtDate())->setId($this->getRequest()->getParam('id'))->save();
                    Mage::getSingleton('adminhtml/session')->addSuccess('successfully saved');
                    Mage::getSingleton('adminhtml/session')->settestData(false);
                    $this->_redirect('*/*/');
                    return;
                }
            } catch (Exception $e){
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            Mage::getSingleton('adminhtml/session')->settestData($this->getRequest()->getPost());
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            return ;
            }
        }
        $this->_redirect('*/*/');
    }
    public function deleteAction()
    {
        if ($this->getRequest()->getParam('id') > 0) {
            try{
                $testModel = Mage::getModel('test/test');
                $testModel->setId($this->getRequest()->getParam('id'))->delete();
                Mage::getSingleton('adminhtml/session')->addSuccess('Successfully deleted');
                $this->_redirect('*/*/');
            } catch (Exception $e){
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            }
        }
        $this->_redirect('*/*/');
    }
}

这是Adminhtml / Test / Edit

中的Form.php
class Best_Test_Block_Adminhtml_Test_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(
            array(
                'id' => 'edit_form',
                'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                'method' => 'post',
                )
            );
        $form->setUseContainer(true);
        $form->setForm($form);
        return parent::_prepareForm();
    }
}

这是Adminhtml / Test / Edit

中的Tabs.php
class Best_Test_Block_Adminhtml_Test_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('test_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle('Information of User');
    }
    protected function _beforeToHtml()
    {
        $this->addTab('form_section', array(
            'label' => 'User information',
            'title' => 'User information',
            'content' => $this->getLayout()->createBlock('test/adminhtml_test_edit_tab_form')->toHtml()
            ));
        return parent::_beforeToHtml()

}     }

这是Adminhtml / Test / Edit / Tab中的Form.php

class Best_Test_Block_Adminhtml_Test_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareform()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('test_form',   array('legend'=>'ref information'));
        $fieldset->addField('name', 'text', array(
            'label' => 'name',
            'class' => 'required-entry',
            'required' => 'true',
            'name' => 'name',
            ));
        $fieldset->addField('email', 'text', array(
            'label' => 'email',
            'class' => 'required-entry',
            'required' => 'true',
            'name' => 'email',
            ));
        $fieldset->addField('password', 'password', array(
            'label' => 'password',
            'class' => 'required-entry',
            'required' => 'true',
            'name' => 'password',
            ));
        if (Mage::registry('test_data')) {
            $form->setValues(Mage::registry('test_data')->getData());
        }
        return parent::_prepareform();  
    }
}

这是app / design / adminhtml / default / default / layout

中的test.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <test_adminhtml_index_index>
        <reference name="content">
            <block type="test/adminhtml_grid" name="test" />
        </reference>
    </test_adminhtml_index_index>
</layout>

为什么我的表单容器中缺少保存和删除? 对不起,如果问题没有得到很好的表达,我是noob magento用户。

0 个答案:

没有答案