简体   繁体   中英

CakePHP: is there a way to convert snake case column names to camel case before sending the JSON response?

I am using a PostgreSQL database where the column names are in snake case, but want them converted to camel case before sending the JSON response. Is this possible in CakePHP?

I tried aliases in select but this breaks the associated records fetching.

For example. My current response is:

[
  {
    "article_id": 1,
    "author_id": 1,
    ...
  }
]

I would like it to be:

[
  {
    "articleId": 1,
    "authorId": 1,
    ...
  }
]

You are most likely looking for sth like https://fractal.thephpleague.com/ A transformer layer between data collecting and data rendering.

Look at this plugin: https://github.com/andrej-griniuk/cakephp-fractal-transformer-view If it is not maintained (I didnt check), you can always fork and maintain that one yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM