I want to display course list in moodle form and using following code;
$options = array();
$allcourses = coursecat::get(0)->get_courses(array('recursive' = true);
foreach ($allcourses as $course) {
$options[$course->id] = $course-fullname;
}
$mform->addElement('select', 'courseid', get_string('course'), $options);
$mform->setDefault('courseid', $currentcourseid);
$mform->setType(PARAM_INT);
But it displays error at $allcourses = coursecat::get(0)->get_courses(array('recursive' = true);
any guidance or help?
Thanks Regards
What does the error message that you are getting say?
Because it looks like you have unbalanced parentheses:
$allcourses = coursecat::get(0)->get_courses(array('recursive' = true);
Try this:
$allcourses = coursecat::get(0)->get_courses(array('recursive' = true));
When in doubt, always make sure your error messages are shown:
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
Or, in your specific case, you might want to amend the Moodle $CFG
object in config.php
:
https://docs.moodle.org/20/en/Debugging
Hope this helps