⚠ 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

use of $this in a callback



richb201

richb201
  • profile picture
  • Member

Posted 08 December 2017 - 14:18 PM

I found this comment in the GC documentation. What does it mean?

 

"It is suggested to use the underscore (_) before the callback name. This is because if you add the underscore at a function in your Controller it is not accessible from the URL. The private and protected method are not accessible from the $this so be careful to not use callbacks as protected or private methods."

 

 

Is the use of THIS the reason that add_email callback doesn't work?

 

function add_email($post_array){

$post_array['email']=base64_decode( urldecode( $this->session->userdata('userid') ) );
return $post_array;

}

 

 


richb201

richb201
  • profile picture
  • Member

Posted 08 December 2017 - 18:05 PM

I figured this out so never mind. I found this in the documentation:

 

Be careful when there are fields that are not included at the fields method then you cannot just add more fields at the callback_before_insert. For example at the current example if we have something like that:

function encrypt_password_callback($post_array) {
$this->load->library('encrypt');
$key = 'super-secret-key';
$post_array['password'] = $this->encrypt->encode($post_array['password'], $key);
 
$post_array['insert_date'] = date('Y-d-m');
$post_array['updated_date'] = date('Y-d-m');
 
return $post_array;
}

 

 

I just added it in fields and then made it invisible. More trial and error. 


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 09 December 2017 - 16:10 PM

Trial and error - is not a process of success and failure .. its a process of learning and succeeding / moving ahead / maturing. It is like and artist moulding his hand do perform a certain style of art with grace.. same is with programing - you have trials / errors where you mould your brain to be move in / ease in solutions around the situations / scenarios like such. Same, in near future wont be a tough call for you.

 

So happy learning and happy GCing :)