When writing an interface controller today, You need to convert the id field in the Data queried from the News table to news_id. Therefore, I directly called the News model that inherits ActiveRecord according to the SQL statement, and the id field in the queried data is missing. {Code...}... when writing an interface controller today
News
The
id
Convert fields
news_id
.
So I directly called the inheritance statement in the SQL statement format.
Active Record
Of
News
Model,
The data is being queried.
id
The field is missing.
$response = News::find()->select(['id AS news_id', 'news_title', 'news_content'])->all();
[ { "news_title": "altestTitile", "news_content": "kasjdfljsdaf" },]
If you directly useQueryBuilder
Query result,id
The field is changednews_id
:
$response = (new Query())->select(['id AS news_id', 'news_title', 'news_content'])->from('tab_user')->all();
[ { "news_id": "1", "news_title": "altestTitile", "news_content": "kasjdfljsdaf" },]
Is the method I used incorrect or is the implementation incomplete due to some bugs in the Yii2 framework?
If you have any questions or want to know more about them, please help us.
Reply content:
When writing an interface controller todayNews
Theid
Convert fieldsnews_id
.
So I directly called the inheritance statement in the SQL statement format.Active Record
OfNews
Model,
The data is being queried.id
The field is missing.
$response = News::find()->select(['id AS news_id', 'news_title', 'news_content'])->all();
[ { "news_title": "altestTitile", "news_content": "kasjdfljsdaf" },]
If you directly useQueryBuilder
Query result,id
The field is changednews_id
:
$response = (new Query())->select(['id AS news_id', 'news_title', 'news_content'])->from('tab_user')->all();
[ { "news_id": "1", "news_title": "altestTitile", "news_content": "kasjdfljsdaf" },]
Is the method I used incorrect or is the implementation incomplete due to some bugs in the Yii2 framework?
If you have any questions or want to know more about them, please help us.
Try ['id' => 'news _ id', 'news _ title', 'news _ content']