0

So in Profile table I created new field named 'rayon_id' which is FK of my new table Rayon's 'id'

both model had the relationship coded.

In Rayon.php

/**
 * @return \yii\db\ActiveQuery
 */
public function getProfiles()
{
    return $this->hasMany(Profile::className(), ['rayon_id' => 'id']);
}

and In Profile.php (Overridden model)

namespace app\models;

use dektrium\user\models\Profile as BaseProfile;

class Profile extends BaseProfile
{
    public function getRayon()
    {
        return $this->hasOne($this->module->modelMap['Rayon'], ['id' => 'rayon_id']);
    }

And here my overridden controller AdminController.php

namespace app\controllers\user;

use dektrium\user\controllers\AdminController as BaseAdminController;
use Yii;
use yii\helpers\Url;
use backend\models\Rayon;

class AdminController extends BaseAdminController
{
    public function actionUpdateProfile($id)
    {
        Url::remember('', 'actions-redirect');
        $user    = $this->findModel($id);
        $profile = $user->profile;
        $rayon = $profile->rayon;

I got an error while added $rayon = $profile->rayon;

enter image description here

Why am I getting the undefined index?

Oldskool
  • 34,211
  • 7
  • 53
  • 66
exneval
  • 43
  • 1
  • 4

1 Answers1

0

Found the answer for fixing the error.

I use Rayon model, and edit the getRayon function

namespace app\models;

use backend\models\Rayon;
use dektrium\user\models\Profile as BaseProfile;

class Profile extends BaseProfile
{
    public function getRayon()
    {
        return $this->hasOne(Rayon::className(), ['id' => 'rayon_id']);
        //return $this->hasOne($this->module->modelMap['Rayon'], ['id' => 'rayon_id']);
}

Thank you.

exneval
  • 43
  • 1
  • 4