creating a simple delete button

Hi Guys,

I have a page that details some information on an object then also returns comments. I'm using a comments hook and not the default comments system.

within the foreach routine that grabs the comments - I'd like either the user that posted the comment or the admin to be able to delete the comment.

within each comment i have saved

$compost->owner_guid as well as a whole bunch of relevant info.

at the very end of the foreach routine as the particular $compost->info is grabbed - I'm not sure if I keep it as simple as something like;

                    if ( $vars['entity']->canEdit() ) {
                    $info .= elgg_view('input/button', array('commentGUID' => $compost->owner_guid, 'action'=>$compost->delete()));


if i need to call an action in which the deletion happens...(and be more specific with the IF routine prior:

if $compost->owner_GUID == $_SESSION['user']->getGUID(); {

// and then an OR if is admin

$info .= elgg_view('input/button', array('commentGUID' => $compost->getGUID(), 'action'=> "{$CONFIG->url}mod/myplugin/actions/comments/delete.php"));


Any thoughts or suggestions - any help greatly appreciated.... :D




  • <?php

    echo elgg_view("output/confirmlink",

      array( 'href' => $vars['url'] . "action/thewire/delete?comment_guid=" . $vars['entity']->getGUID(),


          'text' => elgg_echo('delete'),


          'confirm' => elgg_echo('deleteconfirm'),




  • ese código no funciona me muestra mal el riverdashboard 

  • *bump*

    any idea's as to why my plugin would return the error:

    Fatal error: Call to a member function delete() on a non-object in .../actions/comments/delete.php

    and still actually delete the comment?

    my delete.php now looks like this;

    $guid = get_input('comment_guid');
    $comment = get_entity($guid);
    $returnurl = full_url();

    (english, and this is in no relation to riverdashboard, please).



  • **bump**

    anyone have any ideas what might be causing the fatal error, above?


  • a comment is not an object, it's an annotation. Although I might be way off base. What I'm confused about is that comments have a standard delete link in them anyway. Go to:

    elgg-root/views/default/comments and have a poke around (guessing at the folder name but it's in views/default somewhere)

  • Thanks Trajan - I am basically doing a comment work-around to allow for more input by users. I know the default comment system works as an annotation - but I can't see where in my:

                    $comment = new ElggObject();   
                    $comment->subtype = "comment";   
                    $comment->owner_guid = $_SESSION['user']->getGUID();   
                    $comment->container_guid = $_SESSION['user']->getGUID();
                    $comment->access_id = 1; // logged in users   
                    $comment->parent_guid = $entity_guid;


    ...the $comment is saved as as annotation vs. an object.
    I will try calling delete_annotation() etc.
    (the funny thing is it when using the delete button it returns the fatal error, but then deletes the comment as desired anyway?!)
  • Yes, I've come across similar peculiarities with fatal errors as well. For me it calls a fatal error but still displays the correct content.

  • 1. You are definitely saving the comment as an object according to the code that you posted.

    2. Your delete action looks like it should work. It should have a check after getting the entity to make sure that you actually got something.

    3. An object is not going to be deleted if there is no object to delete. There has to be something else going on here. Basically - we need more information to help.

  • Hi Guys,

    I've created a topic to help cover all the basics of what I'm trying to achieve with the comments system. Hopefully its useful for everyone. And can help resolve the delete functionality.

    Look forward to hearing from you.