在验证为真之前,我将向控制器添加什么以显示消息并停止保存?
class Rsvp extends AppModel {
var $name = 'Rsvp';
var $validate = array(
'uname' => array(
'rule' => array('alphaNumeric', true),
'message' => 'Please enter a vlaid name that does not contain digits'),
'uemail' => array(
'rule' => array('email', true),
'message' => 'Please supply a valid email address.')
);
}
控制器
public function add() {
if ($this->request->is('post')) {
var_dump($this->request->data);
$this->Rsvp->set('uname', $this->request->data['Post']['name']);
$this->Rsvp->set('uemail', $this->request->data['Post']['emailaddress']);
//Begin Validation Routine
echo 'Validation';
var_dump($this->Rsvp->validates);
$this->Rsvp->save();
/*if($this->Rsvp->save()) {
$this->Session->setFlash('You have RSVP for the event');
// $this->redirect(array('action' => 'index'));
}
else {
$this->Session->setFlash('Unable to RSVP you for the event.');
}*/
}
}