Welcome Guest, Not a member yet? Register   Sign In
Number/Currency Formatting
#1

[eluser]ccachor[/eluser]
So I'm loading the price from a database but I need it to display using the number_format function in php. I'm doing a select all and loading it into my view as $data. Where would I format the string? In the controller or the view? I'm doing a foreach in my results as well. I just don't know where to format that string. Help!
#2

[eluser]ccachor[/eluser]
Nevermind, I'm a moron! I figured it out and just format it in the view. That's acceptable practice right?
#3

[eluser]ejangi[/eluser]
Yeah, probably best practice to do that in the view. Some might argue it's a job for the model, but I think the view is a good choice.
#4

[eluser]Phil Sturgeon[/eluser]
It kind of depends really. I used to be the sort of person that would leave the view for NOTHING but output tags (no PHP at all other than if/foreach).

It kind of makes sense to do it in the model if you know thats the data format you will need to use everywhere, but if its just one place it needs to look different, then its a job for the view. It all comes down to which is easier, quicker and which way involves less repeated code or server load.




Theme © iAndrew 2016 - Forum software by © MyBB