gpt4 book ai didi

javascript - JQuery 日期选择器不保存所选日期

转载 作者:行者123 更新时间:2023-12-03 00:50:33 25 4
gpt4 key购买 nike

我在本地主机和服务器上有一个 Cakephp 3.6 项目。我正在使用这个日期选择器:

<?php
echo $this->Form->control('created', ['type' => 'text', 'label' => 'Start date']);
?>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js" ></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#created" ).datepicker({ "dateFormat": "dd-mm-yy"});
} );
</script>

在本地运行时,它会毫无问题地保存所选日期。当我在服务器上使用在线版本时,当我选择日期并提交值时,它会保存今天的日期,而不是所选的日期。

本地主机和服务器之间的文件和数据库是相同的,我只是上传了它们。

编辑(完整代码)

add.ctp

<div class="customerServiceTypes form large-9 medium-8 columns content">
<?= $this->Form->create($customerServiceType) ?>
<fieldset>
<legend><?= __('Add service to customer') ?></legend>
<div ng-app="" ng-init='servicePrices = <?php echo json_encode($servicePrices); ?>;' >
<?php
echo $this->Form->control('customer_id', ['options' => $customers,'label' => 'Customer']);
echo $this->Form->control('service_type_id', ['options' => $serviceTypes, 'label' => 'Service', 'ng-model'=>'service_type_id']);
echo $this->Form->control('price', ['label' => 'Price', 'ng-model'=>'servicePrices[service_type_id]']);
echo $this->Form->control('paid', ['label' => 'Paid', 'type'=>'number']);
echo $this->Form->control('created', ['type' => 'text', 'label' => 'Date from']);
echo $this->Form->control('card', ['label' => 'Card', 'type' => 'checkbox']);
?>
</fieldset>
<?= $this->Form->button(__('Save')) ?>
<?= $this->Form->end() ?>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js" ></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#created" ).datepicker({ "dateFormat": "dd-mm-yy"});
} );
</script>

CustomerServiceTypesController.php

public function add($customerid = null)
{
$customerServiceType = $this->CustomerServiceTypes->newEntity();
if ($this->request->is('post')) {
$customerServiceType = $this->CustomerServiceTypes->patchEntity($customerServiceType, $this->request->getData());
if ($this->CustomerServiceTypes->save($customerServiceType)) {

//debug($this->request->getData("customer_id"),true);
//if field paid is not null then create a credit transaction
if(!is_null($this->request->getData("paid")))
{
$customerServiceType_paid = $this->CustomerServiceTypes->newEntity();
$customerServiceType_paid->customer_id = $customerid;
$customerServiceType_paid->service_type_id = 3; //HARDCODED
$customerServiceType_paid->price = $this->request->getData("paid");
$customerServiceType_paid->created = date("Y-m-d H:i:s");
$customerServiceType_paid->card = $this->request->getData("card");
if ($this->CustomerServiceTypes->save($customerServiceType_paid)) {
$this->Flash->success(__('Success'));
}
else{
$this->Flash->error(__('Fail'));
}
}

$this->Flash->success(__('Success'));

return $this->redirect(['controller' => 'customers', 'action' => 'edit', $customerid]);
}
$this->Flash->error(__('Fail'));
}
$customers = $this->CustomerServiceTypes->Customers->find('list', ['limit' => 200])->where(['Customers.id =' => $customerid]);
$serviceTypes = $this->CustomerServiceTypes->ServiceTypes->find('list', ['limit' => 200]);
$servicePrices = $this->CustomerServiceTypes
->ServiceTypes
->find()
->limit(200)
->combine('id','price');

$this->set(compact('customerServiceType', 'customers', 'serviceTypes','servicePrices'));
}

最佳答案

请求开始日期数据

$this->loadModel('User');
$user=$this->User->get($id);

$startDate = str_replace('/', '-', $this->request->data['start_date']);

$user->start_date $startDate->format('Y-m-d H:i:s');

$this->User->save($user);

关于javascript - JQuery 日期选择器不保存所选日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53063631/

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