开发者

How to format the value in a edit field in cakephp

开发者 https://www.devze.com 2023-04-06 13:56 出处:网络
The price is a float value, and I want to display it like 1.000,00 instead of 1000.00 I know I can use an afterfind callback to change the value, but I will need the original value to do some math.

The price is a float value, and I want to display it like 1.000,00 instead of 1000.00

I know I can use an afterfind callback to change the value, but I will need the original value to do some math.

Is there any callback, like symfony data transformes in cakephp or do I need to use the callback, to create a second field with the formatted value.

Any other options?

echo $this->Form->input('price'); // Price is a float

In the docs and api for FormHelper I could not find开发者_如何学C anything about this.


i recommend using a behavior to "translate" from and to the database. there a tons of them out there. "numeric", "decimal" etc should be the names for it

if you google for those behaviors you find sth like http://float-dot-fixable-behavior.googlecode.com/svn/trunk/float_dot_fixable.php

it can easy be enhanced (both ways):

  • from db: . to ,
  • to db: , to .
0

精彩评论

暂无评论...
验证码 换一张
取 消