【发布时间】:2015-06-18 15:01:15
【问题描述】:
这是我的数据库: http://gyazo.com/c6a86127d6f91aae947cf45ee535cecd
示例: http://gyazo.com/c23fec3fabb7e4504c42453980fbc372 当我按下编辑按钮时,他们可以检索数据,但是页面显示的是空字段,而不是包含旧数据的字段。
其次,无法取消日期,因为他们不断将空 id_field 发送回控制器。
附言添加、编辑、删除方法工作得很好。
以下是我的代码: 型号
<?php
App::uses('AppModel', 'Model');
class EventDate extends AppModel {
public $useTable = 'eventdate';
public $primaryKey = 'eventDate_id';
public $validate = array(
'event_date' => array(
'rule' => array('date','ymd'),
'message' => 'Enter a valid date in YY-MM-DD format.',
'required' => true,
'allowEmpty' => false
)
);
}
控制器
public function edit($id = null) {
//Retrieve from database
$post = $this->EventDate->findByEventdateId($id);
$this->set('edate', $post) ;
// debug($post);
//Without Id
if (!$id) {
throw new NotFoundException(__('Invalid Event Date'));
}
//If Not Exist the id
if (!$post) {
throw new NotFoundException(__('Invalid Event Date'));
}
//After press the submit
if ($this->request->is(array('post','put'))) {
$this->EventDate->eventDate_id = $id;
debug($_POST);
if ($this->EventDate->save($this->request->data)) {
$this->Session->setFlash(__('The Event has been saved.'));
return $this->redirect(array('action' => 'index'));}
else
{$this->Session->setFlash(__('The Event could not be saved. Please, try again.'));}
}
//Set the data same as retrieved
if (!$this->request->data) { $this->request->data = $post;}
}
edit.ctp
<h2>Edit Event</h2>
<?php
echo $this->Form->create('eventdate');
//echo $this->Form->input('eventDate_id', array('type' => 'hidden'));
echo $this->Form->hidden('eventDate_id');
echo $this->Form->input('event_date',array(
'label' => 'Event Date',
'type' => 'text',
'id' => 'datepicker'));
echo $this->Form->end('Save Post');
?>
下面的链接是显示的调试($_Post): http://gyazo.com/5e569e6cc6b3026fc8896c315197a938
【问题讨论】:
标签: cakephp sql-update