In my cakephp project the save function is not working?
Posted
by Faheem
on Stack Overflow
See other posts from Stack Overflow
or by Faheem
Published on 2010-05-02T07:47:45Z
Indexed on
2010/05/02
7:57 UTC
Read the original article
Hit count: 282
My controller action is:
function add() {
if (!empty($this->data)) {
$this->Customer->create();
if ($this->Customer->save($this->data)) {
$this->Session->setFlash('A new Customer has been added');
$this->redirect(array('action'=>'index'));
}
else {
$this->Session->setFlash('The customer cannot be added this time. Try again later.');
$this->redirect(array('action'=>'index'));
}
}
}
My model is:
class Customer extends AppModel {
var $name = 'Customer';
var $validate = array(
'name' => array(
'length'=> array(
'rule' => array('between', 4,50),
'message' => 'Name must be minimum 4 and maximum 50 characters long.'
),
'checkUnique'=> array(
'rule' => 'isUnique',
'message' => 'This Name is already registered'
)
));
and this is my view:
create('Customer',array('action'=>'add'));?> input('Customer.name'); echo $form->input('Customer.balance',array('type'=>'hidden','default'=>0)); ?> end('Submit');?>every time I submit the form it splashes: The customer cannot be added this time. Try again later.
© Stack Overflow or respective owner