I wanna save some data on database in cakephp. here is my code...
public function addout()
{
$uid = $this->Auth->User()['id'];
$out = $this->Outs->newEntity();
if ($this->request->is('post')) {
$out = $this->Outs->patchEntity($out, $this->request->data);
$this->request->data['user_id'] = $uid;
}
if ($this->Outs->save($out)) {
$this->Flash->success(__('The out has been saved.'));
} else {
$this->Flash->error(__('The out could not be saved. Please, try again.'));
}
}
and here is my template
<?php
echo $this->Form->create();
echo $this->Form->input('out time:', array('class' => 'outtime', 'id' => 'outtime', 'name' => 'outtime' ));
echo $this->Form->input('out date :', array('class' => 'datepicker0', 'id' => 'outdate', 'name' => 'outdate', 'type' => 'text'));
echo $this->Form->input('return date:', array('class' => 'datepicker0', 'id' => 'returndate', 'name' => 'returndate', 'type' => 'text'));
echo $this->Form->input('distance :', array('class' => 'distance', 'id' => 'distance', 'name' => 'distance', 'type' => 'textarea'));
echo $this->Form->input('phone number:', array('class' => 'phonenumber', 'id' => 'phonenumber', 'name' => 'phonenumber', 'type' => 'text'));
echo $this->Form->button(__('submit'));
echo $this->Form->end();
?>
but when I run it out put is:The out could not be saved. Please, try again. my database is ...
please help.
答案 0 :(得分:1)
Call method errors() on entity $out->errors()
to see validations errors
if ($this->Outs->save($out)) {
$this->Flash->success(__('The out has been saved.'));
} else {
debug($out->errors()); die;
$this->Flash->error(__('The out could not be saved. Please, try again.'));
}