【问题标题】:OctoberCMS Backend List format number field as a currencyOctoberCMS 后端列表格式数字字段作为货币
【发布时间】:2017-01-10 18:13:04
【问题描述】:

想知道是否有一种简单的方法来格式化后端列表列值。将数字值作为货币的示例

【问题讨论】:

    标签: octobercms


    【解决方案1】:

    来晚了,仅供参考:

    如果仅用于后端列表,您可以轻松地创建一个新的列类型 Currency 并使用它。 see documentation

    在您的情况下,您可以在 Plugin.php 中添加以下内容:

    public function registerListColumnTypes()
    {
      return [
        'currency' => function($value) { 
                           return money_format( $value, 2);
                           }
        ];
    }
    

    现在您可以在插件的每个 coulmns.yaml 中使用它:

    columns
      title:
        label: Title
        type: text
      amount:
        type: currency
        label: Amount
    

    【讨论】:

      【解决方案2】:

      我建议根据 10 月的 (Laravel) 文档在您的模型上添加一个访问器

      https://octobercms.com/docs/database/mutators

      <?php
      class YourModel
      {
          public function getCurrencyColumn($value)
          {
              return money_format('%i', $value)
          }
      }
      

      【讨论】:

      • 我也是这么想的
      猜你喜欢
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      相关资源
      最近更新 更多