【问题标题】:magento how add dynamic url path in system.xmlmagento 如何在 system.xml 中添加动态 url 路径
【发布时间】:2013-11-02 12:32:11
【问题描述】:

我正在开发支付网关。但我有问题我做了谷歌研究但找不到任何解决方案我希望我能在这里得到解决方案所以我在这里发帖

按照我的 system.xml 代码块

<title translate="label">
    <label>Title</label>
    <comment><![CDATA[<img src="/media/billmate/images/billmate_bank_s.png" />]]></comment>
    <frontend_type>text</frontend_type>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</title>

在这个块问题现在在评论标签中,我在这里放了静态链接/media/billmate/images/billmate_bank_s.png 请任何人建议我如何使它成为动态

【问题讨论】:

  • 你到底想做什么?
  • 使用 magento 对吧?
  • 是的,使用 magento 1.7
  • @R.S 我现在正在尝试制作动态评论标签,评论标签包含不正确的静态图像路径

标签: magento system.xml


【解决方案1】:

system.xml 中的元素可以有动态注释。评论可以通过模型呈现。
您需要像这样声明评论字段:

<comment>
    <model>module/adminhtml_comment</model>
</comment>

现在您需要使用别名 module/adminhtml_comment 创建模型:

<?php
class Namespace_Module_Model_Adminhtml_Comment{
    public function getCommentText(){ //this method must exits. It returns the text for the comment
        return "Some text here";
    }
}

喜欢关注

<title translate="label">
    <label>Title</label>
    <comment>
        <model>module/adminhtml_comment</model>
    </comment>
    <frontend_type>text</frontend_type>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</title>

getCommentText 方法的返回值

【讨论】:

    【解决方案2】:

    添加到 system.xml 文件中

    <field id="row_payment_us_free" translate="label" type="select" sortOrder="5" showInDefault="1" showInStore="1" showInWebsite="1" canRestore="1">
        <label>Payment US Free</label>
        <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
        <comment><model>VendoreName\ModuleName\Model\SystemConfigComment</model></comment>
    </field>
    

    app/code/VendoreName/ModuleName/Model

    SystemConfigComment.php

    <?php
    
    namespace VendoreName\ModuleName\Model;
    
    use Magento\Framework\UrlInterface;
    
    class SystemConfigComment implements \Magento\Config\Model\Config\CommentInterface
    {
        protected $urlInterface;
    
        public function __construct(
            UrlInterface $urlInterface
        ) {
            $this->urlInterface = $urlInterface;
        }
    
        public function getCommentText($elementValue)
        {
            $url = $this->urlInterface->getUrl('adminhtml/system_config/edit/section/payment');
    
            return 'Require to enable <a href="' .$url . '#row_payment_us_free" target="_blank">Zero Subtotal Checkout</a>payment method for Zero Subtotal order.';
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 2016-08-31
      • 2015-11-04
      • 2021-05-27
      相关资源
      最近更新 更多