M
M
Maxim2018-02-06 20:28:11
Yii
Maxim, 2018-02-06 20:28:11

Why doesn't it output $dataProved?

Tell me what I'm doing wrong? Need to get related data out of profile...

Controller
/**
     * Lists all Awards models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new AwardsSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
Conclusion
<?php foreach ($dataProvider->getModels() as $award):?>
                            <div class="awards-index-card col-sm-4">

                                <div class="awards-index-img">
                                    <a href="<?= yii\helpers\Url::to(['/awards/view','id'=> $award->id])?>">
                                        <img class="img-responsive" src="<?=$award->getFullImgUrl()?>">
                                    </a>
                                    <div class="awards-social">
                                        <?php
                                            if ($award->profile->vk){
                                                echo  Html::a('<i class="fa fa-vk"></i>',$award->profile->vk, ['target'=>'_blank']);
                                            }
                                            if ($award->profile->instagram) {
                                                echo Html::a('<i class="fa fa-instagram"></i>', $award->profile->instagram, ['target'=>'_blank']);
                                            }
                                        ?>
                                    </div>
                                </div>
                                <div class="awards-info">
                                    <a href="<?= yii\helpers\Url::to(['/awards/view','id'=> $award->id])?>">
                                        <!--<div class="awards-index-title"><?/*=$award->profile->getFullName()*/?></div>-->
                                    </a>
                                    <div class="awards-index-nomination"><?=$award->nomination->name?></div>
                                    <div class="awards-index-year"><?=$award->year?> </div>
                                </div>
                            </div>
                        <?php endforeach; ?>

It is not possible to withdraw by connection $award->profile->vk, but it $award->nomination->namedisplays

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-06
@myks92

Good evening.
Well, I understand that $dataProvider is not empty, since it displays $award ...
But why is foreach() here?
Isn't it easier to use a ListView?
No, it's not easier, it's even better!
And it will not be necessary to sculpt everything through $dataProvider->getModels(), but already through $model. And connections can be made.
But this already needs to be looked at by SearchModel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question