The first thing you have to know to become a Moodle developer is know the program structure in Moodle.
And a simple example is to create a custom page that is connected with Moodle application.
There are several variables of the Moodle system that you need to know.
$CFG = for information website like baseurl etc. $DB = conntecting to database moodle. $OUTPUT = for calling strutur in template moodle like header footer. $PAGE= set information page like title breadcrump etc.
I will try to practice making a simple page with the structure we already know . Create a new folder in the root directory of moodle for example newcustompage and create a file with the name index.php put this code :
<?php
//CALL CONFIG DATABASE
require_once('../config.php');
//TITLE AND BREADCRUMB
$PAGE->set_title('New Custom Page');
$PAGE->navbar->add("New Custom Page");
//CALL HEADER PAGE
echo $OUTPUT->header();
//LINE FOR CONTENT PAGE
echo "Content";
echo $CFG->wwwroot;
//CALL FOOTER PAGE
echo $OUTPUT->footer();
Then try to run
Next I try to display data from the database into the page. Before that we must know how to use the $DB variable.
// SELECT multiple data
$DB->get_records_sql("SELECT * FROM {course}");
//SELECT row
$DB->get_record_sql("SELECT * FROM {course} WHERE id=1");
And let's to try<?php
//CALL CONFIG DATABASE
require_once('../config.php');
//TITLE AND BREADCRUMB
$PAGE->set_title('New Custom Page');
$PAGE->navbar->add("New Custom Page");
//CALL HEADER PAGE
echo $OUTPUT->header();
//LINE FOR CONTENT PAGE
//SELECT multiple data
$data = $DB->get_records_sql("SELECT * FROM {course} LIMIT 5");
$content = '<table class="table">
<tr>
<td>ID COURSE</td>
<td>COURSE NAME</td>
</tr>';
foreach ($data as $key => $value) {
$content .= '
<tr>
<td>'.$value->id.'</td>
<td>'.$value->fullname.'</td>
</tr>';
}
$content .='
</table>';
echo $content;
//SELECT row
$data = $DB->get_record_sql("SELECT * FROM {course} WHERE id=1");
echo $data->fullname;
//CALL FOOTER PAGE
echo $OUTPUT->footer();
If you want to develop better please go to the official Moodle website and read the documentation.
Good luck !
0 Comments