⚠ 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

avoid deletion in before delete callback



David Leiva
  • profile picture
  • Member

Posted 26 September 2012 - 17:12 PM

Hi All,

I'm try to avoid the deletion of the superadmin..

To do this, I set the before delete callback,

$crud->callback_before_delete(array($this,'_avoid_delete_admin_callback'));

function _avoid_delete_admin_callback($post_array, $primary_key = null){
return ($primary_key != 1); // it shoud not allow to delete registrer 1.
}

I thought that returning false abort the deleltion operation.. but it does not.

I've not found anything about this in the documentation..
is posible to do that ?

thanks

David Leiva
  • profile picture
  • Member

Posted 26 September 2012 - 17:18 PM

Ok, sorry.. in fact.. it works...

victor
  • profile picture
  • Member

Posted 26 September 2012 - 17:19 PM

HI!


<? var_dump($primary_key != 1);?>

result : bool(true)!

David Leiva
  • profile picture
  • Member

Posted 26 September 2012 - 17:38 PM

( $primary_key != 1 ) returns true where primary key is not 1. if is equal 1 returns false..

php -r '$primary_key=1;var_dump($primary_key != 1);'
bool(false)


anyway, I've realized that the problem is that $primary_key is empty.. ... so returning false directly, it works.. but i dont have the primary_key code..

Maybe a Bug ?

victor
  • profile picture
  • Member

Posted 26 September 2012 - 17:41 PM

function _avoid_delete_admin_callback( $primary_key)
It takes one parameter - the primary key value. The return value is not required for this callback.
Your function have two parameters: function _avoid_delete_admin_callback($post_array, $primary_key = null)

David Leiva
  • profile picture
  • Member

Posted 26 September 2012 - 17:50 PM

AGGG, yeahhhhh ... that was the mistake!!!!

I dont know why I had two parameters.. surely copy and paste from another callback... :P

Thank you victor.
;)