17

I am a complete newbie in CakePHP. I want to read the field names of the table in the controller.

I want the controller to list all the field names in the table. How do I do that?

Kevin
  • 41,694
  • 12
  • 53
  • 70
Asim Zaidi
  • 27,016
  • 49
  • 132
  • 221

3 Answers3

26

Use the following snippet to get an array of the field names (replace "YourModel" with the name of your model):

array_keys($this->YourModel->getColumnTypes());
dhofstet
  • 9,934
  • 1
  • 36
  • 37
16

as simple as $this->Model->schema()

mark
  • 21,691
  • 3
  • 49
  • 71
6

For CakePHP 3.x

$this->Model->schema() - Returns the Schema object.

$this->Model->schema()->columns() - Returns all of the columns in the table in an array.

Dooltaz
  • 2,413
  • 1
  • 17
  • 16