gpt4 book ai didi

cakephp-3.0 - Cakephp 3 如何在数据库中保存单个日期

转载 作者:行者123 更新时间:2023-12-03 17:28:41 29 4
gpt4 key购买 nike

我有请假申请表。如果用户请假2/3天,那么请假日期应该单独存储到数据库中。我申请了2天,假设我选择了20-10-2019和21-10- 2019 年请假。但是它只存储了一个条目到数据库中。 date_form 和 date_to 是我的列名。
我想分开日期。示例: date_from: 20-10-2019 date_to : 20-10-2019 和 date_from: 21-10-2019 date_to : 21-10-2019。
但现在它存储了 date_from : 20-10-2019 date_to : 21-10-2019。谁可以帮我这个事?

我试过一些代码:

            else if($leaveRequest->no_of_days > 1 && $leaveRequest->no_of_days < 7)
{
for($i = 0 ; $i < $leaveRequest->no_of_days; $i++)
{
$day = $i. ' day';
$var = $this->EmpLeaves->newEntity();

if($i == 0)
{
$var->date_from = date('Y-m-d', strtotime($this->request->getData(['date_from'])));
$var->date_to = date('Y-m-d', strtotime($this->request->getData(['date_from'])));
}

else
{
$var->date_from = date('Y-m-d', strtotime($day,strtotime($this->request->getData(['date_from']))));
$var->date_to = date('Y-m-d', strtotime($day,strtotime($this->request->getData(['date_from']))));
}

$var->employee_id = $this->Auth->user('id');
$var->employee_name = $this->request->getData(['employee_name']);
$var->reporting_managerId = $this->request->getData(['reporting_managerId']);
$var->leave_type = $this->request->getData(['leave_type']);
// $var->no_of_days = $this->request->getData(['no_of_days']);
$var->no_of_days = 1;
$var->half_day = $this->request->getData(['half_day']);
$var->leave_reason = $this->request->getData(['leave_reason']);
$var->reliever = $this->request->getData(['reliever']);
$valueSaved = $this->EmpLeaves->save($var);
}

if($valueSaved)
{
//newcode for sending email
$applierEmail = $this->Auth->user('office_email');
$applierName = $this->Auth->user('first_name') . ' ' . $this->Auth->user('last_name');

}
else
{
$this->Flash->error(__('Please check the message'));
}
}

最佳答案

         else if($leaveRequest->no_of_days > 1 && $leaveRequest->no_of_days < 7)
{
for($i = 0 ; $i < $leaveRequest->no_of_days; $i++)
{
$day = $i. ' day';
$var = $this->EmpLeaves->newEntity();



else

$var->date_from = date('Y-m-d', strtotime($day,strtotime($this->request->getData(['date_from']))));
$var->date_to = date('Y-m-d', strtotime($day,strtotime($this->request->getData(['date_to']))));


$var->employee_id = $this->Auth->user('id');
$var->employee_name = $this->request->getData(['employee_name']);
$var->reporting_managerId = $this->request->getData(['reporting_managerId']);
$var->leave_type = $this->request->getData(['leave_type']);
$var->no_of_days = $this->request->getData(['no_of_days']);
$var->half_day = $this->request->getData(['half_day']);
$var->leave_reason = $this->request->getData(['leave_reason']);
$var->reliever = $this->request->getData(['reliever']);
$valueSaved = $this->EmpLeaves->save($var);
}

if($valueSaved)
{
//newcode for sending email
$applierEmail = $this->Auth->user('office_email');
$applierName = $this->Auth->user('first_name') . ' ' . $this->Auth->user('last_name');

}
else
{
$this->Flash->error(__('Please check the message'));
}
}

关于cakephp-3.0 - Cakephp 3 如何在数据库中保存单个日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58128570/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com