S
S
Snewer2016-06-10 18:06:20
Yii
Snewer, 2016-06-10 18:06:20

How to get dynamic properties when outputting from ActiveRecord as an array?

Hello!
The ActiveRecord model has a getValueText(){ ... } getter that formats the Value as I need it.
If the data is converted to an array (when requested) ->asArray, valueText does not get into it. Is it possible to implement this somehow?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-06-10
@Snewer

Override extraFields()your model
www.yiiframework.com/doc-2.0/guide-structure-model...

The extraFields() method defines additionally available fields which can also be returned by toArray() as long as you specify them via the $expand parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question