我有3张桌子看起来像这样
Employee Table
id | EmpId | Name |
1 | N1 | A |
2 | N2 | B |
3 | N3 | C |
Leave Table
id | EmpId | applydate | startdate | daysleave | reason | status |
1 | N2 | 2016-08-25 | 2016-08-25 | 4 | vacation | Approved |
Setting Table
id | var | val | valdef | status |
1 | MaxLeave | 12 | 12 | 1 |
每位员工最多可享受12天的设置表 如果daysleave = 4,那么maxleave应该是8天。 我是怎么做到的?我应该在员工表上添加新字段吗? 结果预期:
答案 0 :(得分:1)
您可以在模型中创建get函数以检索您需要的信息示例:
public function getDaysOfLeaveLeft() {
// query for the data you need and return days left
return $days;
}
然后在视图中显示它
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'daysOfLeaveLeft',
],
]) ?>
修改强>
全功能
public function getDaysOfLeaveLeft() {
$models = LeaveTable::findAll(['EmpId' => $this->EmpId]);
$leave = 0;
foreach ($models as $model) {
$leave += $model->daysleave;
}
$setting = Setting::find(['var' => 'MaxLeave']);
return $setting->val - $leave;
}