H
H
hollanditkzn2017-04-05 17:33:40
Yii
hollanditkzn, 2017-04-05 17:33:40

Why exit null value in related table?

The fact is that I have related tables, but it turns out that I get only id, but I tried it in wardump <?php var_dump($zakaz) ?>, I get null
The code I wrote is this in the database model is connected

public function getIdZakaz()
    {
        return $this->hasOne(Zakaz::className(), ['id_zakaz' => 'id_zakaz']);
    }

I wrote in the controller
public function actionIndex()
    {
        $searchModel = new CourierSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
        $zakaz = Courier::findOne($id_zakaz);
        $zakaz->IdZakaz->description;

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'zakaz' => $zakaz,
        ]);
    }

When displaying a value in the grid
[
                'attribute' => 'id_zakaz',
                'format' => 'text',
                'value' => $zakaz,
            ],

I have this field in Zakaz table
public function attributeLabels()
    {
        return [
            'id_zakaz' => '№',
           ....
            'description' => 'Описание',
  ...
        ];
    }

What exactly did I do wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question