【问题标题】:entity number formating in phalcon form voltphalcon形式的实体编号格式伏特
【发布时间】:2016-11-23 16:10:31
【问题描述】:

问题

我想呈现带有格式值的表单文本。

案例

[input:text] // 这是文本输入

[5000] // 这是我没有number_format()的文本输入

[5.000] // 这是我的目标

代码:

$protQty   = new Text('protQty',[
    'placeholder'   => 'Jumlah Pesan ( Hanya Angka ) ',
    'class'         => 'form-control ',
    'value'         => number_format($entity->protQty,0,",","."), //unworking code
    'readonly'      => true
]);
$protQty->setLabel('Jumlah Permintaan');
$this->add($protQty);

【问题讨论】:

  • 你现在得到什么输出?您的 number_format 应该会产生所需的输出。
  • @Timothy,你好! :D 简而言之,我想要输出 5.000,正如我上面解释的那样,但那是我的代码不适用于 number_format()-ing $entity->protQty
  • $entity->protQty 背后隐藏着什么价值,你能var_dump 看看吗?

标签: forms number-formatting phalcon volt


【解决方案1】:

您应该修改实体。如果实体可用,则覆盖字段值。

执行以下操作:

$entity->protQty = number_format($entity->protQty, 0, ",", ".");

$protQty = new Text('protQty',[
    'placeholder' => 'Jumlah Pesan ( Hanya Angka ) ',
    'class' => 'form-control ',
    // Not needed anymore
    // 'value' => number_format($entity->protQty,0,",","."), //unworking code
    'readonly' => true
]);

其他选项是在模型中使用 getter/setter 始终以所需格式输出数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多