Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model field data formatting #3

Open
smgladkovskiy opened this issue Feb 23, 2011 · 1 comment
Open

Model field data formatting #3

smgladkovskiy opened this issue Feb 23, 2011 · 1 comment

Comments

@smgladkovskiy
Copy link

In master branch of Jelly we had form items generating. In this functional there was a data formatting mechanism (such as pretty_format for timestamps) that helped to convert data that was requested from the database in database (or some other) format to a readable to the user format.

In 3.1 unstable branch we offer to make a 'format' method that will be in model and tries to format a field data to represent it in some pretty format that was set in the model meta ('pretty_format' in field properties).

It would be defined in model meta initialization like something this:

'birthday' => Jelly::field('Timestamp', array(
    'pretty_format' => 'd.m.Y',
)),

/* for Integer fields would be used number_format function and params
 * for pretty_format should set as 
 * array(int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
 */
'price' => Jelly::field('Float', array(
    'pretty_format' => array(2, ',', ' ')),
)),
'monkeys' => Jelly::field('String', array(
    'pretty_format' => '[%010s]\n', // sprintf format is set
)),

And will be called like that:

// fields formats
echo $model->format('birthday'); // will echo formatted date:   04.02.1999
echo $model->format('price');    // will echo formatted price:  12 000,25
echo $model->format('monkeys');  // will echo formatted string: [0000monkey]
@biakaveron
Copy link
Member

Additional suggestion: add optional param $format, so we can set custom field format, for example $model->format('birthday', 'd.m.y')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants