[英]how to display time from db table into drop downlist yii2?
this is my form field for dropdown list Time
这是我的下拉列表
Time
表单字段
<?= $form->field($model, 'Time')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Schedule::find()->where(['username' => 'cust_id', 'day'=>'Day_cust','availability'=>'available'])->all(),'time','time'),
'language' => 'en',
'options' => ['placeholder' => 'Select available time ...'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
Day_cust
and cust_id
is taken from the previous text input in the same form which is field by the user. Day_cust
和cust_id
取自先前输入的文本,格式相同,由用户输入。
I have tried the above code but it failed to display the time available. 我已经尝试了上面的代码,但是无法显示可用时间。
this is my model for schedule 这是我的时间表模型
public function attributeLabels()
{
return [
'schedule_id' => 'Schedule ID',
'username' => 'Username',
'day' => 'Day',
'time' => 'Time',
'availability' => 'Availability',
];
}
what I want is I want to display on the drop-down list for time
the time input in the database with the availability available
based on cust_id
and day
insert by the user in the field. 我要的是我要在下拉列表中显示
time
与可用性数据库的时间输入available
基于cust_id
和day
嵌在该领域的用户。
how should I do it? 我该怎么办?
if anyone wonder why i dont use dependent dropdownlist is because the cust_id is using text input same goes with the day. 如果有人想知道为什么我不使用依赖的dropdownlist是因为cust_id使用的文本输入与当天相同。 i didnt use the ddl for both of them.
我没有对他们两个都使用DDL。
In your ArrayHelper::map()
, make sure you have used correct database field values. 在
ArrayHelper::map()
,确保使用了正确的数据库字段值。
Your database field contains time
not Time
, So ArrayHelper
should be like, 您的数据库字段包含
time
而不是Time
,因此ArrayHelper
应该像这样,
ArrayHelper::map(Schedule::find()->where(['username' => 'cust_id', 'day'=>'Day_cust','availability'=>'available'])->all(),'time','time')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.