A
A
Artem Prokhorov2021-07-27 23:34:19
Yii
Artem Prokhorov, 2021-07-27 23:34:19

Is it possible to change the name of a database column when rendering via REST?

Well, that is, do not change the name itself in the database, namely, so that the table has a field username, but when I received the data of this table via REST, the field was usernamedisplayed Логинin the json body, is that possible?

{
   "Логин": "some_login",  // но в таблице бд, столбец называется username
   "age": 1000
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2021-07-28
@kotcich

Here you go https://www.yiiframework.com/doc/guide/2.0/en/rest...

V
Vitaliy K, 2021-07-28
@revenger

Is this something needed?

model::find()
            ->select('username as login')
            ->where(['id' => $id])
            ->one();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question