Accessing the moodle api from an external file

Accessing the moodle api from an external file

by Manuel Saint-Victor -
Number of replies: 3
I am attempting to customize the quiz module to create another view.  I am having trouble with an error :
Fatal error: Call to a member function on a non-object in    ..... /moodle/lib/datalib.php on line 487

This occurs in a page that I created that I would like to give access to the moodle api and the functions defined throughout moodle.  I have read that it is because the $db variable failed to be defined globally  and was curious if I could just define it temporarily but I worry that this will be the first of many undefind variables that I run into by me entering from a "side page"  is there a way to manually define the needed parts by including certain files while I am testing? 

I know that this is a poorly stated question but I am not certain how to clarify it.

Any help would b appreciated.  Thanks in advance.


Average of ratings: -
In reply to Manuel Saint-Victor

Re: Accessing the moodle api from an external file

by Penny Leach -
really silly question - you are doing

require_once('path/to/config.php');

right?
In reply to Penny Leach

Re: Accessing the moodle api from an external file

by Manuel Saint-Victor -
not a silly question by far.  yeah i have that as well as

 require_once("../lib.php");


In reply to Manuel Saint-Victor

Re: Accessing the moodle api from an external file

by Penny Leach -
can you post your code maybe?

$db should always be created during the process that is started by including config.php (which includes lib/setup.php) - and the line you reference is inside get_record_sql - which explicitly does global $db at the start of the function...

unless you're doing something to $db yourself perhaps?

I can't help more than that without you posting your code smile