Problems with the "Hello World" example? Or am I missing something here?

Hi everyone,

I'm pretty new to elgg. I was learning how to create basic plugins in elgg 1.7.7
There is a tutorial on how to create your first basic "Hello World" widget here: http://docs.elgg.org/wiki/Tutorials/HelloWorld

Everything went fine till the part "Allow User Customization". No matter what I try, I cannot get this working.

The string that the user enters is saved in $widget->message
But it is NOT CARRIED OVER to the view.php (OR content.php in elgg 1.8).

The variable $widget->message is UNSET in view.php and as a result, no text appears.

I hope I have been pretty clear regarding my problem. I have followed the tutorial word by word. Is there an error in the tutorial (I highly doubt it) or am I missing something BIG here?

Please help me out with this issue. I feel I'm overlooking some really basic things here.

Many Thanks! :)

  • Would need to see your code to comment.

  • start.php contains:

    <?php
    function hello_init() {        
        elgg_register_widget_type('helloworld', 'Hello, world!', 'The "Hello, world!" widget');
    }
     
    register_elgg_event_handler('init', 'system', 'hello_init');       
    ?>

    edit.php contains:

    <div>
        <label>Message:</label> 
    <?php 
        //This is an instance of the ElggWidget class that represents our widget.
        $widget = $vars['entity'];
     
        // Give the user a plain text box to input a message
        echo elgg_view('input/text', array(
            'name' => 'params[message]', 
            'value' => $widget->message,
            'class' => 'hello-input-text',
        )); 
    ?>
    </div>

    view.php contains:

    <?php 
        $widget = $vars['entity'];
     
        // Always use the corresponding output/* view for security!
        echo elgg_view('output/text', array('value' => $widget->message)); 
    ?>
  • Skullo,

    Your code is mixing Elgg 1.8 and Elgg 1.7.x requirements. Eg., you are using view.php (Elgg 1.7.x) but elgg_register_widget_type() (Elgg 1.8). As Elgg 1.8 has not been released yet, it would be safer to stick to 1.7.x. Read the wiki again and note the differences.

  • Looks like we need separate 1.7 and 1.8 documentation. Here is the 1.7 only hello world tutorial: http://docs.elgg.org/w/index.php?title=Tutorials/HelloWorld&oldid=3657

  • Hey Cash and Kevin... Thanks a lot for your help. I finally figured out the problems. There were two issues:

    1) I had to replace "elgg_register_widget_type()" with "add_widget_type()" as suggested.

    2) And I also had to make another small change in the edit.php file.
    'name' => 'params[message]' had to be modified to
    'internalname' => 'params[message]'

    Thanks a lot! :)