为什么我的adminhtml“新”操作页面没有在Magento中显示?

时间:2012-08-15 21:25:46

标签: magento

对于我的自定义模块的管理面板/brands/adminhtml_brand/new/中的这个,当我想要向数据库添加新条目时,我应该会看到一个页面。我following this tutorial。我的layout.xml设置正确。

magento cannot edit

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

Edit.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');
        }
    }

}

Grid.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',

2 个答案:

答案 0 :(得分:2)

根据您尝试访问的网址,您的控制器操作应为newAction(),而不是editAction(),除非您已经按照教程中的那样转发了newAction()进行编辑。

您链接的教程包括从newAction到editAction的转发,使用:

public function newAction()
{
    $this->_forward('edit');
}

因此,要么确保您正在使用该转发,要么在/brands/adminhtml_brand/edit/访问控制器,如果这样做,请务必更新布局句柄以定位编辑路径。

要解决的一些事情:

  • 首先,将所有相关代码发布到SO问题 - 包括布局xml更新
  • 始终包含所有magento类/文件的完整类名或文件路径。因为看起来你似乎没有做过明显错误的事情,它可能会归结为一些琐碎的事情,比如拼写错误或不匹配的块类型/名称 - 这种情况多次发生在我身上。
  • 如果您尚未
  • ,请停用缓存
  • 启用块模板提示,以确保将哪些模板和块拉入页面。
  • 检查exception.log,system.log以及PHP错误日志,看看是否有任何内容。

答案 1 :(得分:0)

您可能遇到ACL问题(magento安全性)。

有关详细信息,请参阅here