# Simplest code to get list of all column names in table

**URL:** <https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295>\
**Category:** Uncategorized\
**Created:** [April 26, 2021, 11:58am UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295 "2021-04-26T11:58:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user\_looser](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/user_looser/32/2161_2.png) [@user\_looser](https://discourse.cakephp.org/u/user_looser)\
**Post date:** [April 26, 2021, 11:58am UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295/1 "2021-04-26T11:58:44Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 26, 2021, 2:52pm UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295/2 "2021-04-26T14:52:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![user\_looser](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/user_looser/32/2161_2.png) [@user\_looser](https://discourse.cakephp.org/u/user_looser)\
**Post date:** [April 26, 2021, 6:45pm UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295/3 "2021-04-26T18:45:47Z")

</div>

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:

 ![get all cols names](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/1/1d0afd47facdd231937a80f8ef046656e94831a0.png)

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

 ![error](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/a/a87ea8a531b654aa8c2f53786cadb28140d0094c.png)

Thank you!

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 26, 2021, 9:18pm UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295/4 "2021-04-26T21:18:27Z")

</div>

In Cake4, all the combined getter/setter functions like “schema” have been removed, and instead are pairs like “[getSchema](https://api.cakephp.org/4.0/class-Cake.ORM.Table.html#getSchema())/[setSchema](https://api.cakephp.org/4.0/class-Cake.ORM.Table.html#setSchema())”.

---

<div class="post-metadata">

**Author:** ![user\_looser](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/user_looser/32/2161_2.png) [@user\_looser](https://discourse.cakephp.org/u/user_looser)\
**Post date:** [April 27, 2021, 5:35am UTC](https://discourse.cakephp.org/t/simplest-code-to-get-list-of-all-column-names-in-table/9295/5 "2021-04-27T05:35:44Z")

</div>

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

 ![result](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/4936d12ad5cf21a15a0ed07adddd64b69cfedf08.png)
