Answer the question
In order to leave comments, you need to log in
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
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,
]);
}
}
public function geti18n(){
return $this->hasMany(i18n::className(), [
'object_id' => 'country_id',
]);
}
public function getCountries()
{
return $this->hasOne(Countries::className(), ['country_id' => 'object_id']);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question