Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my database model, my attribute is set as type INT.

On the front end, I want to display a select field with representative values for the respective Integer values.

eg: [1 = Home, 2 = About]

I am currently using an external plugin for the administrating content, and the select values only allows integer. So my idea is to achieve this at respective Model. Is it possible?

share|improve this question

2 Answers

Genarally yes.

You should be able to attach results of Model->find('list') to select field. Of course your model should have name or title fields for description values (Home, About).

share|improve this answer

Sounds like the kind of enum representation as I always use. Try this solution: http://www.dereuromark.de/2010/06/24/static-enums-or-semihardcoded-attributes/

I basically uses an array matching to resolve those ints into strings in a clean way - using the model. can be the whole array for select fields or just the specific string for output in the view/index.

Its also fully form and bake-template capable. If you name the field "attribute" in your table, and name the method "attributes()" you can easily have "cake bake" to bake this via custom templates.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.