General developer forum

Create/handle button in view.php

Picture of Richard Jones
Re: Create/handle button in view.php
Particularly helpful MoodlersPlugin developersTesters

Here's what I can suggest:

1. Download moodle-mod_NEWMODULE from Moodle HQ's GitHub account.  

2.  Follow the instructions carefully and test that it installs and works.

3. Near the lines 'Yay, it works!' add something like this:

// Replace the following lines with you own code.
echo $OUTPUT->heading('Yay! It works!');
$link = new moodle_url('/mod/widget/view.php', ['id' => $cm->id]);
echo html_writer::link($link, get_string('click', 'mod_widget'), ['class' => 'btn btn-primary']);

You will have a button that sends you back to the view.php page (ie the one you are already on).  What you could then do is copy and rename the view.php page and modify it to display data you obtain from the database, say in a table.  

Other html_writer functions can be found here (or browse the source code):

Hope this will help you get started.


Average of ratings: -