I have made relation between Buku and Guest. I want to add link download ebook in guest's email. Field link_dl
in table Buku.
In common\models\Buku
public function getGuest()
{
return $this->hasOne(Guest::className(), ['id_buku' => 'id_buku']);
}
In common\models\Guest
public function getBuku()
{
return $this->hasMany(Buku::className(), ['id_buku' => 'id_buku']);
}
In Controller
if($model->load(Yii::$app->request->post()))
{
$value = Yii::$app->mailer->compose()
->setFrom('myaccount@gmail.com')
->setTo($model->email)
->setSubject('Download Ebook')
->setTextBody($model->buku->link_dl) //link download ebook $model->relationName->field_name
->send();
$model->save();
But I get an error,
exception 'yii\base\ErrorException' with message 'Trying to get property of non-object'
What is the issue in here? Thankyou. It's Solved