V
V
Vyacheslav2016-11-22 16:40:53
MySQL
Vyacheslav, 2016-11-22 16:40:53

How to display information from two tables?

Good afternoon,
I am currently learning yii2.
There are two models i18n and Countries, both models correspond to tables and are inherited from ActiveRecord
Through Crud created actions, brought Data from two tables into the index.
At the moment I'm stuck on actionUpdate
Could you show by example how to display all fields from two tables in Update, but in the Countries table everything is simple (one line)
Example of i18n table
a4b98dad1cfd47d6bd269c4a2feb3d9c.png
Standard code

public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->country_id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

Relationship of tables in Countries
public function geti18n(){
        return $this->hasMany(i18n::className(), [
            'object_id' => 'country_id',
        ]);
    }

Communication in i18n
public function getCountries()
    {
        return $this->hasOne(Countries::className(), ['country_id' => 'object_id']);
    }

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-11-22
@slo_nik

Good afternoon.
Maybe this article will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question