# \[SOLVED\] CakePHP3 get table fields info (schema)

**URL:** <https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274>\
**Category:** Need Help\
**Created:** [September 26, 2017, 7:57pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274 "2017-09-26T19:57:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xv1t](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xv1t/32/821_2.png) [@xv1t](https://discourse.cakephp.org/u/xv1t)\
**Post date:** [September 26, 2017, 7:57pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/1 "2017-09-26T19:57:15Z")

</div>

How in the CakePHP 3 get all fields info from the table model?

For example, in the CakePHP2, method of model `schema`.

```php
$fields = $this->Article->schema();

//return
$fields = [
  'id' => [
     'type' => 'integer',
     'comment' => null,
     'size' => 11,
     'length' => 10,
     'key' => 'primary'
   ],
   'name' => [
     'type' => 'string',
     'length' => 255,
     'comment' => 'Enter a name for article, please...',
     'default' => null
   ],
   /* ... other fields ...*/
];

```

but in CakePHP dont finded analog of this…

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [September 27, 2017, 3:09pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/2 "2017-09-27T15:09:13Z")

</div>

[https://api.cakephp.org/3.5/class-Cake.Database.Schema.TableSchema.html](https://api.cakephp.org/3.5/class-Cake.Database.Schema.TableSchema.html)

---

<div class="post-metadata">

**Author:** ![xv1t](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xv1t/32/821_2.png) [@xv1t](https://discourse.cakephp.org/u/xv1t)\
**Post date:** [September 27, 2017, 5:21pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/3 "2017-09-27T17:21:10Z")

</div>

Thanks. It’s great!  
[https://book.cakephp.org/3.0/en/orm/schema-system.html#schema-collections](https://book.cakephp.org/3.0/en/orm/schema-system.html#schema-collections)

```php
        // insert into begin of the controller file
        use Cake\Datasource\ConnectionManager;

        $db = ConnectionManager::get('default');

        // Create a schema collection.
        $collection = $db->schemaCollection();

        // Get a single table (instance of Schema\TableSchema)
        $tableSchema = $collection->describe('articles');
        
        //Get columns list from table
        $columns = $tableSchema->columns();
        
        //Empty array for fields
        $fields = [];
        
        //iterate columns
        foreach ( $columns as $column ){
            $fields[$column] = $tableSchema->column( $column );
        }

```

And now - in the `$fields` return:

```php
[
	'id' => [
		'type' => 'integer',
		'length' => (int) 10,
		'unsigned' => false,
		'null' => false,
		'default' => null,
		'comment' => '',
		'autoIncrement' => true,
		'precision' => null
	],
	'name' => [
		'type' => 'string',
		'length' => (int) 255,
		'null' => false,
		'default' => null,
		'collate' => 'utf8_general_ci',
		'comment' => 'Артикль',
		'precision' => null,
		'fixed' => null
	],
	'description' => [
		'type' => 'string',
		'length' => (int) 255,
		'null' => true,
		'default' => null,
		'collate' => 'utf8_general_ci',
		'comment' => '',
		'precision' => null,
		'fixed' => null
	],
	'article_good_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => 'Товарная группа артикля',
		'precision' => null,
		'autoIncrement' => null
	],
	'disabled' => [
		'type' => 'boolean',
		'length' => null,
		'null' => true,
		'default' => '0',
		'comment' => '',
		'precision' => null
	],
	'date_expired' => [
		'type' => 'date',
		'length' => null,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null
	],
	'article_type_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null,
		'autoIncrement' => null
	],
	'producer_company_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => 'Производитель',
		'precision' => null,
		'autoIncrement' => null
	],
	'supplier_company_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => 'Поставщик',
		'precision' => null,
		'autoIncrement' => null
	],
	'created' => [
		'type' => 'datetime',
		'length' => null,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null
	],
	'updated' => [
		'type' => 'datetime',
		'length' => null,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null
	],
	'created_user_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null,
		'autoIncrement' => null
	],
	'updated_user_id' => [
		'type' => 'integer',
		'length' => (int) 11,
		'unsigned' => false,
		'null' => true,
		'default' => null,
		'comment' => '',
		'precision' => null,
		'autoIncrement' => null
	]
]

```

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [September 27, 2017, 6:56pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/4 "2017-09-27T18:56:14Z")

</div>

You are welcome

Why woud you need this?

---

<div class="post-metadata">

**Author:** ![xv1t](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xv1t/32/821_2.png) [@xv1t](https://discourse.cakephp.org/u/xv1t)\
**Post date:** [September 27, 2017, 7:29pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/5 "2017-09-27T19:29:01Z")

</div>

Im developing a frontend jQuery plugin online full records control table component with REST requests and CakePHP 3 server side. with full search,inserting, updating lookup fields and more

This fields info needed for autobuil columns, types, comment.

After the first beta release, a want publicate this project on the [github.com](http://github.com). Interest it?

![Снимок экрана_2017-09-27_20-19-24](https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex029/uploads/cakephp/original/1X/bb194001c5fd89597bcc0d7a9fab6da330ad3b0f.jpg)

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [September 28, 2017, 8:11am UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/6 "2017-09-28T08:11:31Z")

</div>

So you would create something like phpmyadmin… Good luck!  
Yes, sure I am interested.

---

<div class="post-metadata">

**Author:** ![xv1t](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xv1t/32/821_2.png) [@xv1t](https://discourse.cakephp.org/u/xv1t)\
**Post date:** [September 28, 2017, 8:28am UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/7 "2017-09-28T08:28:42Z")

</div>

Thanks  
I’m oriented on `MS Access's` like desktop windowed application via web ui. (chromium/chrome browser app-mode)  
You have a github account?

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [September 28, 2017, 8:47am UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/8 "2017-09-28T08:47:52Z")

</div>

Yes [https://github.com/rrd108/](https://github.com/rrd108/)

---

<div class="post-metadata">

**Author:** ![xv1t](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/xv1t/32/821_2.png) [@xv1t](https://discourse.cakephp.org/u/xv1t)\
**Post date:** [October 3, 2017, 5:32pm UTC](https://discourse.cakephp.org/t/solved-cakephp3-get-table-fields-info-schema/3274/9 "2017-10-03T17:32:38Z")

</div>

Hi, Im publicated a table component projects in the [github.com](http://github.com).  
Manual and docs in progress.

This is a deep developing beta 🙂 with bugs and simple functionality. But main idea is present

> **[xv1t/untable](https://github.com/xv1t/untable)**
>
> untable - jQuery table plugin

Wiki url: [https://github.com/xv1t/untable/wiki](https://github.com/xv1t/untable/wiki)
