Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yii 2.0.16 with() asArray() how to support fields() rewriting? #17208

mydzoo opened this issue Mar 14, 2019 · 1 comment


3 participants
Copy link

commented Mar 14, 2019

User: ActiveRecord

public function fields()
    return array_merge(parent::fields(), [
        'avatar' => function () {
            if (!preg_match('/^http(s)?:\\/\\/.+/', $this->avatar)) {
                return Yii::$app->params['storageUrl'] . $this->avatar;
            return $this->avatar;

Post: ActiveRecord

public function getCreator()
    return $this->hasOne(User::class, ['id' => 'created_by']);


public function actionIndex()
    $posts = Post::find()->with(['creator'])->asArray()->all()
    return [
        'posts' => $posts

with() how to support fields() rewriting? Instead of passing expand parameter?

asArray()Although association information can be displayed, it has not been rewritten by fields ().

Is there any other way to achieve it?

@samdark samdark added the question label Mar 14, 2019


This comment has been minimized.

Copy link

commented Mar 14, 2019

Thank you for your question.
In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

This is an automated comment, triggered by adding the label question.

@yii-bot yii-bot closed this Mar 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.