⚠ 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

Custom Add, Edit and Delete Operations?



tanver

tanver
  • profile picture
  • Member

Posted 08 December 2011 - 11:45 AM

Know there must be a simple solution to the problem I am faced with, want to know how can I completely replace the operations performed when an Add, Edit or Delete button is pressed?
TIA

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 08 December 2011 - 19:44 PM

[quote name='tanver' timestamp='1323344759' post='104']
Know there must be a simple solution to the problem I am faced with, want to know how can I completely replace the operations performed when an Add, Edit or Delete button is pressed?
TIA
[/quote]
For now the only way to do it is to use getState method. You can see it at http://www.grocerycrud.com/crud/function_name/getState .

tanver

tanver
  • profile picture
  • Member

Posted 08 December 2011 - 19:56 PM

[quote name='web-johnny' timestamp='1323373456' post='105']
For now the only way to do it is to use getState method. You can see it at http://www.grocerycr...n_name/getState .
[/quote]
You mean after having checked the state, we can just add our own code to do the things .. like for delete action I just want to set the Active Column to a ZERO value .. and that is it.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 08 December 2011 - 20:02 PM

[quote name='tanver' timestamp='1323374180' post='106']
You mean after having checked the state, we can just add our own code to do the things .. like for delete action I just want to set the Active Column to a ZERO value .. and that is it.
[/quote]
For this you can use simply callbacks. For example in your case you can use callback_escape_delete http://www.grocerycr...k_escape_delete . So it escapes the auto delete and you can add your own.You can see an example of a callback at http://www.grocerycr...k_before_insert For now I still don't have an example for the delete. Just remember that to the callback function that you will create you will have the primary key value.

The are plenty functions of callbacks that you can see here: http://www.grocerycrud.com/crud/view/options_functions

tanver

tanver
  • profile picture
  • Member

Posted 08 December 2011 - 20:09 PM

It would have been great if there was an example available for anyone of the callbacks for add/edit, will certainly give it a try and let the community know. Thanks for your kind help.

xxaxxo

xxaxxo
  • profile picture
  • Member

Posted 09 December 2011 - 06:54 AM

I'm sorry to bump you up - but I have a thread on the delete callback - asking for a simple example , and you seem to have missed it ... (5 days in a row) if it's not a big problem , can you just explain how can we get the primary key value to the callback function that we create, and when we are talking about a _n_n relational row - which primary key is sent ?
A short example will be greatly appreciated.
Thank you for your time!


1 more thing i forgot to mention, is there anyway to debug the callback functions , because a simple print_r and die doesn't really work. So i guess many people are like me , they don't know what they are working on and is it working at all with the callbacks.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 10 December 2011 - 12:39 PM

[quote name='xxaxxo' timestamp='1323413656' post='109']
I'm sorry to bump you up - but I have a thread on the delete callback - asking for a simple example , and you seem to have missed it ... (5 days in a row) if it's not a big problem , can you just explain how can we get the primary key value to the callback function that we create, and when we are talking about a _n_n relational row - which primary key is sent ?
A short example will be greatly appreciated.
Thank you for your time!


1 more thing i forgot to mention, is there anyway to debug the callback functions , because a simple print_r and die doesn't really work. So i guess many people are like me , they don't know what they are working on and is it working at all with the callbacks.
[/quote]

The only thing that you can do to take the primary key of the insert is to use the callback_after_insert . So the callback that you will have to use this will have two parameters. The post_array that includes the n_n relation and the primary_key so you will create a function similar to this:


function exampe_callback_after_insert($post_array, $primary_key)
{
.....
}


I know that my documentation is really pure for the most of callbacks and it's good that user's understand them even without the documentation that's good ;-) . Of course I try to do my best to have documentation of the most used callbacks.

Now for the second question. I know it's really annoying to don't have a debug mode for the callbacks, and it's really annoying even for me to don't I have an option. I actually use the log_message of codeigniter to test if something works fine. It's not the best solution I know but it's better to use this kind of function than print_r() and die(). The most of calls are ajax calls and there is a problem with debugging. So a temporary solution may be to use the log_message

fdias

fdias
  • profile picture
  • Member

Posted 07 June 2012 - 15:36 PM

I know this is and old thread but now since we can unset the operations couldn't we have something like this:

$crud->unset_edit();
$crud->add_action('Edit', 'URL_TO_ICON.png', array($this,'SOME_FUNCTION'));

Hope this helps someone.