⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Callback before update question



joansd4n
  • profile picture
  • Member

Posted 02 October 2013 - 19:11 PM

Hello, 
 
I want to send a mail whit a variable when a row is delete from the crud. I used this code:
$crud->callback_before_delete(array($this, 'send_mail'));
 
function send_mail ($post_array, $primary_key)
  {
    $config['wordwrap']= TRUE;
    $config['mailtype']= 'html';
    $config['charset']= 'utf-8';
    $config['crlf']= "\r\n";
    $config['newline']= "\r\n";
 
    $Eliminado= date('Y-m-d H:i:s');
    $this->load->library('email');
    $this->email->initialize($config);
 
    $this->email->from('mail@sendmail.com','example');
    $this->email->to('mimail@sendmail.com');
    $this->email->cc('othermail@sendmail.com');
 
    $this->email->subject('Registro eliminado en el Sistema ');
    $this->email->message("Estimado ".$post_array['username']." se ha eliminado la información de un usuario en su plataforma. Fecha de Modificación:".$Eliminado.""); 
    $this->email->send();
 
    echo $this->email->print_debugger();
  }
 
This works for insert and update rows, but when i delete a row does not return a value.
 
Any suggestions?
 
Thanks.

 


davidoster
  • profile picture
  • Member

Posted 11 October 2013 - 03:59 AM

Hello and welcome to the forums [member=joansd4n].

The callback_before_delete has as parameters only the $primary_key. Please modify your code.


joansd4n
  • profile picture
  • Member

Posted 17 October 2013 - 15:21 PM

Thanks for the reply David,

 

I found the solution, this is the code I'm using:

 

$crud->callback_before_delete(array($this, 'send_mail'));
 
function send_mail ($primary_key)
  {
    $query= mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 1");
    $result= mysql_fetch_array($query);
    $variable= $result['variable'];

 

    $config['wordwrap']= TRUE;
    $config['mailtype']= 'html';
    $config['charset']= 'utf-8';
    $config['crlf']= "\r\n";
    $config['newline']= "\r\n";
 
    $Eliminado= date('Y-m-d H:i:s');
    $this->load->library('email');
    $this->email->initialize($config);
 
    $this->email->from('mail@sendmail.com','example');
    $this->email->to('mimail@sendmail.com');
    $this->email->cc('othermail@sendmail.com');
 
    $this->email->subject('Registro eliminado en el Sistema ');
    $this->email->message("Estimado ".$variable." se ha eliminado la información de un usuario en su plataforma. Fecha de Modificación:".$Eliminado.""); 
    $this->email->send();
 
    echo $this->email->print_debugger();
  }
 

Regards.