Simplest code to get list of all column names in table

Hello, what is the simplest way to get an array of table columns names in controler? I found this elsewhere: $this->Model->schema()->columns(), nevertheless it doesnot work … Please could anyone help me and describe the code in detail? Thank you!

What version of Cake are you using? What error do you get with the code you’ve tried?

Thank you for your help. I use version 4.2.5, I need to get an array with column names in my controller index action.

Here is the code:

And here is the error (I declared to use Cake\Database\Scheme):

Thank you!

In Cake4, all the combined getter/setter functions like “schema” have been removed, and instead are pairs like “getSchema/setSchema”.

1 Like

You saved so much of my time! Thank you very much!

For all others - solution is: $cols = $this->YourModelName->getSchema()->columns(); e.g. in my case I used $cols = $this->Rulings->getSchema()->columns();

1 Like