简体   繁体   English

php yii2表单字段取决于表单字段

[英]php yii2 form field depend on out-of-form field

I am searching for a solution to my problem in php/yii2. 我在php / yii2中寻找问题的解决方案。 I am using DependDropdown widget. 我正在使用DependDropdown小部件。

To guide : My currently working (lets say 'Application') table has columns: 指导:我当前正在使用的表(请说“应用程序”)具有以下列:

1.  Id    
2.  student_id
3.  university_id    [....rest....]

In my ActiveForm I have a dropdownlist with lets say students names. 在我的ActiveForm中,我有一个下拉列表,可以说学生姓名。 They are grouped in model, but in case if there would be students with the same name and surname I want to add Depend Dropdown with Personal Identify Number to choose specific person. 他们在模型中分组,但是如果有学生使用相同的姓名和姓氏,我想添加带有个人识别码的“依赖下拉列表”以选择特定的人。 But column with this number is from another table than my $model . 但是带有该数字的列是来自我$model以外的另一个表。 Application table has student_id column, and I want to get that student_id to ActiveForm , but by searching it from my Dropdown with personal ID. 应用程序表中有student_id列,我想将该Student_id转到ActiveForm,但是要通过带有个人ID的Dropdown搜索它。 I try to show it on example 我尝试在例子中展示

<droplist with names > I choose for example Carl Dickens <droplist with names >我选择例如卡尔·狄更斯

<droplist with Personal number>

Case 1: Okay, in DB students table there is only 1 Carl Dickens. 情况1:好的,在DB学生表中只有1个卡尔·狄更斯。 So there is only 1 number to choose from droplist 因此,只有1个数字可供选择

Case 2: There are some Carls Dickens in DB. 情况2: DB中有一些卡尔·狄更斯。 All Carl Dickens personal numbers are dropped to dropdown list, so u can choose correct one by it 所有卡尔·狄更斯(Carl Dickens)的个人号码都将落入下拉列表,因此您可以通过它选择正确的一个

<droplist with Personal number> is not a column from $model (Application) table, and that's my problem in ActiveForm. <droplist with Personal number>不是$model (应用程序)表中的列,这是ActiveForm中的问题。 Can somebody help me? 有人可以帮我吗? Thanks 谢谢

Please declare $personal_number as a variable in your model 请在模型中将$ personal_number声明为变量

class Application extends ActiveRecord
{

public $personal_number;


.....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM