Skip to content

Instantly share code, notes, and snippets.

@lenamuit
Created May 6, 2012 09:48
Show Gist options
  • Save lenamuit/2621319 to your computer and use it in GitHub Desktop.
Save lenamuit/2621319 to your computer and use it in GitHub Desktop.
Cakephp: add/edit/delete record
function admin_add(){
//TODO: check retype password
if (!empty($this->data)){
$this->Product->set($this->data);
if ($this->Product->validates()){
if ($this->Product->save($this->data)){
$this->Session->setFlash("Add member successfull");
}
else{
$this->Session->setFlash("Add member fail");
}
$this->redirect(array('action'=>'index'));
}else{
//$this->Session->setFlash(explode(',', $this->Product->invalFields()));
}
}
}
function admin_delete($id){
if (isset($id) && !empty($id)){
$this->Product->delete($id);
}
$this->redirect(array('action'=>'index'));
}
function admin_edit($id){
$this->Product->id = $id;
if (!empty($this->data)){
$this->Product->set($this->data);
if ($this->Product->validates()){
if ($this->Product->save($this->data)){
$this->Session->setFlash("Add member successfull");
}
else{
$this->Session->setFlash("Add member fail");
}
$this->redirect(array('action'=>'index'));
}else{
//$this->Session->setFlash(explode(',', $this->Product->invalFields()));
}
}
else{
$this->data = $this->Product->read();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment