Asim Zaidi
Asim Zaidi

Reputation: 28344

How to get the field names of the table in CakePHP

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?

Upvotes: 17

Views: 13476

Answers (3)

Dooltaz
Dooltaz

Reputation: 2463

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.

Upvotes: 6

mark
mark

Reputation: 21743

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

Upvotes: 16

dhofstet
dhofstet

Reputation: 9964

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());

Upvotes: 26

Related Questions