0

I have a Classroom model, which has an INT field called level. The values for this field can range from 1-7. What I would like to do is translate the integer in that field into a String for display, according to a predetermined legend, such as this:

1 - Basic I
2 - Basic II
3 - Basic III
4 - Intermediate I

etc... What would be the best way of achieving this? Using afterFind()?

Thanks

2
  • 1
    See also: stackoverflow.com/questions/6924574/… Commented Oct 10, 2011 at 14:11
  • Can I create associations to an ArraySource model? It doesn't seem to work :S Commented Oct 10, 2011 at 15:34

2 Answers 2

2

Why not make an extra table containing strings matching the ID of the INT field called level. Get the string from that table using the matching ID and your good to go.

Sign up to request clarification or add additional context in comments.

1 Comment

yeap I could definitely do that.
0

the quickest way (if the strings do not change much!):

http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/

echo Classroom::levels($classroom['Classroom']['level']); 

in the view - whereever you need it

it also uses less resources than any other approach (therefor is the fastest).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.