yii2 多步骤形式

yii2 multi step form

刚刚习惯yii2

Am creating a multistep form in yii2 which involves three related tables

User table:has         (idno(primary key), firstname, secondname and lastname)
Education table has:  (idno(foreign key), institution_name, year_completed, grade)
Contacts table has:   (idno(f.key),contact)

模型和关系

关系 btwn 用户和联系人

 public function getContacs()
{
    return $this->hasMany(Contacts::className(), ['idno' => 'idno']);
}
 public function getUser()
{
    return $this->hasOne(User::className(), ['idno' => 'idno']);
}

用户与教育的关系

public function getEducation()
{
    return $this->hasMany(Education::className(), ['idno' => 'idno']);
}

public function getUser()
{
    return $this->hasOne(User::className(), ['idno' => 'idno']);
}

我如何创建一个多步骤表单,用户在第一步中填写他的详细信息,然后在教育详细信息的下一步中,表单自动选择用户 ID 并将其传递给教育详细信息,直到完成

您需要为每个步骤维护一个标志,例如 first_step = 0,second_step = 0 third_step = 0。如果填写了第一步,请更改 first_step = 1 对其他内容执行相同操作,此字段应出现在用户 table 中,或者您可以使用用户 ID 作为外键维护另一个 table。如果 first_step = 1 那么当您再次登录时,页面将打开,其中 flag = 0 表示它将直接打开第二步。这是一个基本概念所以你可以理解,还有其他方法。