且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento - 覆盖 adminhtml 模板文件

更新时间:2023-11-30 10:23:16

Adminhtml 使用与前端相同的主题回退,因此您只需要在模块配置 XML 中为您的安装声明一个自定义模板主题:

Adminhtml uses the same theming fallback as the frontend, therefore you need only declare a custom template theme for your installation in module config XML:

<stores>
    <admin>
        <design>
            <theme>
                <template>custom</template>
            </theme>
        </design>
    </admin>
</stores>

然后您可以使用您喜欢的任何自定义创建app/design/adminhtml/default/custom/template/widget/grid.phtml,并且该文件将优先于来自默认/默认 adminhtml 主题.您的解决方案是在呈现导出控制的逻辑中添加 ACL 检查:

Then you can create app/design/adminhtml/default/custom/template/widget/grid.phtml with any customizations you like, and this file will be used in preference to the one from the default/default adminhtml theme. Your solution then would be to add an ACL check in the logic which renders the export control:

<?php if($this->getExportTypes() && {ACL LOGIC}}): ?>
    <td class="export a-right">
        <img src="<?php echo $this->getSkinUrl('images/icon_export.gif') ?>" alt="" class="v-middle"/>&nbsp; <?php echo $this->__('Export to:') ?>
        <select name="<?php echo $this->getId() ?>_export" id="<?php echo $this->getId() ?>_export" style="width:8em;">
        <?php foreach ($this->getExportTypes() as $_type): ?>
            <option value="<?php echo $_type->getUrl() ?>"><?php echo $_type->getLabel() ?></option>
        <?php endforeach; ?>
        </select>
        <?php echo $this->getExportButtonHtml() ?>
    </td>
<?php endif; ?>

虽然这个逻辑可能更适合在块类中实现,但类重写系统不适应父类的重写,让您重写每个子类.在这种情况下,遵守 DRY 比在模板中嵌入太多逻辑更重要.而且,变化明显且易于维护.

While this logic might be more appropriately implemented in the block class, the class rewrite system does not accommodate rewriting of parent classes, leaving you to rewrite every subclass. In this instance, obeying DRY outweighs embedding too much logic in templates. Moreover, the change is obvious and easily maintained.

理想情况下,核心团队会在 Mage_Adminhtml_Block_Widget_Grid 类中实现这个检查,或者至少为 _exportTypes 属性提供一个公共设置器,这会使这个逻辑有点实施起来更干净.

Ideally the core team would have implemented this check in the Mage_Adminhtml_Block_Widget_Grid class or at least provided a public setter for the _exportTypes property, which would have made this logic a bit cleaner to implement.