E
E
Evgeny Startsev2015-06-25 21:14:29
Yii
Evgeny Startsev, 2015-06-25 21:14:29

How to change field names in yii2?

Hello.
How to specify a new field name in the query builder?
This is the source code

$query = News::find()
    ->select(['name', 'SUBSTRING(`text`, 1, 256 ) as `text`', 'date', 'id'])
    ->where($where['where'], $where['arr']);

And you need to get a field of such a plan
'SUBSTRING(`text`, 1, 256 ) as `text2`'
, but it doesn’t work ... when outputting, it swears at the absence of text2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Papa, 2015-06-25
@jey_val_star

Declare text2 as a public property of the News class.
public text2;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question