Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 300
Asim Zaidi Avatar asked Apr 30 '11 06:04

Asim Zaidi


3 Answers

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());
like image 57
dhofstet Avatar answered Sep 26 '22 08:09

dhofstet


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

like image 43
mark Avatar answered Sep 26 '22 08:09

mark


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.

like image 29
Dooltaz Avatar answered Sep 23 '22 08:09

Dooltaz