magento中的面包屑(breadcrumb)

565 查看

记录下有关magento关于面包屑的笔记:
magento的后台有很多类似button标签的按钮,比如:

在项目中,我们会对这些面包屑添加一些增删改查的一些功能,这也是面包屑的主要功能之一,但是当有时候项目的一些模块也不需要这些面包屑,那么如何去掉它呢?
1.如何去掉右上方的面包屑(Add New):

//在block/Adminhtml/XXX.php中的构造方法中添加一行代码即可
class YourModule_Custom_Block_Adminhtml_Custom extends Mage_Adminhtml_Block_Widget_Grid_Container
{
  public function __construct()
  {
    $this->_controller = 'adminhtml_custom';
    $this->_blockGroup = 'custom';
    $this->_headerText = Mage::helper('custom')->__('Custom Manager');
    parent::__construct();
    //$this->_addButtonLabel = Mage::helper('custom')->__('Add Item');
    //删除Add new,添加如下代码:
    $this->_removeButton('add');
  }
}

删除后的效果如图:

2.如何更改面包屑的名称(重命名面包屑):

//在上述构造方法中取消对这行的注释即可:
$this->_addButtonLabel = Mage::helper('custom')->__('Add Item');

3.Magento后台Grid点进去后的Edit页面,也包含了Back、Save和Delete按钮,如何来去除这些按钮呢?
首先,来看下未操作之前的展示图:

删除之后的展示图:

如何做的?来看下下面的这段代码:

//Block/Adminhtml/Count/Edit.php 页面
class Message_Count_Block_Adminhtml_Count_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();  
        $this->_objectId = 'id';
        $this->_blockGroup = 'count';
        $this->_controller = 'adminhtml_count';
        //删除delete按钮
        $this->_removeButton('delete');
        //删除save按钮
        $this->_removeButton('save');
        //删除back按钮
        $this->_removeButton('back');
        //删除reset按钮
        $this->_removeButton('reset');
        //更改save按钮的名称
        $this->_updateButton('save', 'label', Mage::helper('count')->__('Save Item'));
        //更改delete按钮的名称
        $this->_updateButton('delete', 'label', Mage::helper('count')->__('Delete Item'));
        //添加面包屑Save And Continue Edit 
         $this->_addButton('saveandcontinue', array(
            'label'     => Mage::helper('adminhtml')->__('Save And Continue Edit'),
            'onclick'   => 'saveAndContinueEdit()',
            'class'     => 'save',
        ), -100);

        $this->_formScripts[] = "
            function toggleEditor() {
                if (tinyMCE.getInstanceById('count_content') == null) {
                    tinyMCE.execCommand('mceAddControl', false, 'count_content');
                } else {
                    tinyMCE.execCommand('mceRemoveControl', false, 'count_content');
                }
            }

            function saveAndContinueEdit(){
                editForm.submit($('edit_form').action+'back/edit/');
            }
        ";
    }