因此,在Profile表中,我创建了名为“rayon_id”的新字段,这是我的新表Rayon 'id‘的FK
这两种模型都有编码的关系。
在Rayon.php中
/**
* @return \yii\db\ActiveQuery
*/
public function getProfiles()
{
return $this->hasMany(Profile::className(), ['rayon_id' => 'id']);
}在Profile.php (重写模型)中
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']);
}在这里,我被重写的控制器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;我在添加$rayon = $profile->rayon;时出错了

为什么我要得到未定义的索引?
发布于 2016-08-18 10:19:51
找到了修复错误的答案。
我使用人造丝模型,并编辑getRayon函数
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']);
}谢谢。
https://stackoverflow.com/questions/39014772
复制相似问题