【发布时间】:2017-01-10 18:13:04
【问题描述】:
想知道是否有一种简单的方法来格式化后端列表列值。将数字值作为货币的示例
【问题讨论】:
标签: octobercms
想知道是否有一种简单的方法来格式化后端列表列值。将数字值作为货币的示例
【问题讨论】:
标签: octobercms
来晚了,仅供参考:
如果仅用于后端列表,您可以轻松地创建一个新的列类型 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
【讨论】:
我建议根据 10 月的 (Laravel) 文档在您的模型上添加一个访问器
https://octobercms.com/docs/database/mutators
<?php
class YourModel
{
public function getCurrencyColumn($value)
{
return money_format('%i', $value)
}
}
【讨论】: