0

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
na9090
  • 125
  • 2
  • 13

2 Answers2

0

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).

jodator
  • 2,445
  • 16
  • 29
0

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.

mark
  • 21,691
  • 3
  • 49
  • 71