ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Integrating with Moodle (problem)

August 11, 2007 10:38pm

Subscribe [3]
  • #1 / Aug 11, 2007 10:38pm

    Jay Jennings

    11 posts

    I’m using Moodle as a shell for some of my online tools—creating a “course” that links to an external page (also on the same server as Moodle).

    But now I’m trying to switch over to CodeIgniter for my PHP development (I love it!) and am having some problems. Specifically, for the external PHP pages to use the Moodle vars, I need to include this line at the top of my pages:

    include(”/path/to/Moodle/config.php”);

    That allows my pages to make sure the user is logged in to Moodle, etc. But when I try to include that line in my controller file, I get this error:

    A PHP Error was encountered
    Severity: User Notice
    Message: Fatal: $CFG->wwwroot is not configured! Exiting.
    Filename: lib/setup.php
    Line Number: 88

    I believe that’s coming from Moodle, not CI, but I’m kind of lost as to why it’s happening and what to do to fix it.

    Have I given anyone enough information to point me in the right direction?

    Thanks!

    Jay Jennings

  • #2 / Aug 11, 2007 10:41pm

    Jay Jennings

    11 posts

    Just something else that may help.

    This is the code that’s causing the error message:

      if (!isset($CFG->wwwroot)) {
    trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.');
    die;
    }

    And I don’t believe what it says because every other external (and internal) page on the site works.

    Thanks.

    Jay Jennings

  • #3 / Aug 12, 2007 1:29am

    esra

    485 posts

    CodeIgniter’s front controller instantiates the Config library as $CFG in Codeigniter.php at line 79 (v1.54) but the line number could be different for other versions. $CFG is only used in two places within CodeIgniter. You might try to temporarily change the variable to something else in both places (the second place is line 91 in the same file) just to see if this is causing a conflict.

  • #4 / Aug 12, 2007 1:46am

    Jay Jennings

    11 posts

    Wow, I had great hopes for that—it sounded like a quick and easy fix. I found all the locations in CI where $CFG was referenced and changed them to $ciCFG and uploaded those files—only to find there was no change in the problem.

    I even switched to a different machine just to make sure there wasn’t a browser caching issue.

    Any ideas from anyone else?

    Thanks.

    Jay Jennings

  • #5 / Aug 12, 2007 3:07am

    esra

    485 posts

    Is moodle running independently?

    What is the wwwroot parameter set to in moodle’s config.php?

    Where is moodle installed in relation to application/?

  • #6 / Aug 12, 2007 3:26am

    Jay Jennings

    11 posts

    Yes, Moodle is running independently. I have other tools (pre-CI) running fine.

    This is what Moodle see in the config file:

      $CFG->wwwroot   = ‘http://sonictoolkit.com/members’ ;

    I know that file is being loaded by the controller because the last line in that file does a require_once and it’s *that* file that spits out the error.

    Moodle is running in that folder shown above, and the app is down here:

    http://sonictoolkit.com/members/external/split/index.php/listpages/

    You can hit that, but then try and click one of the items in the list and you’ll see the error message show up.

    At the top of the page showing the error I had it spit out APPPATH just for the fun of it (so I could figure out where things were).

    Thanks.

    Jay Jennings

  • #7 / Aug 12, 2007 3:44am

    esra

    485 posts

    I managed to get moodle running under another framework some time ago and will try to do the same with CI. Will get back soon.

  • #8 / Aug 12, 2007 3:49am

    Jay Jennings

    11 posts

    Thanks, I appreciate the help.

    I’m wondering at the wording you used in your last message, so I wanted to make clear that I’m not trying to “merge” CI and Moodle to any great degree—Moodle lets you run code in a framed window and take advantage of the user’s login info, etc.

    I can run “plain” PHP programs like that just fine, but when I try to include the Moodle config file inside CI, that’s where things fall apaer.

    Thanks.

    Jay Jennings

  • #9 / Aug 12, 2007 4:59am

    esra

    485 posts

    You can probably get it to work using an iframe embedded in a view. But, you will probably need to let moodle’s index.php handle the config file loading.

    Aside from using the same $CFG variable name, moodlelib includes a function called get_config which is also a function in CI’s common.php. Loading moodle from a controller without using an iframe would require hacks in one or the other application.

  • #10 / Oct 30, 2008 12:39pm

    Allen Dino

    6 posts

    Hi Jay, (sorry, didn’t notice that this thread was old.  :lol: )

    I have that exact same issue! I need to load moodle variables in CI so that I can be able to create CI pages (which is faster rather than tinkering with Moodle’s code) that rely on Moodle session variables. But I can’t seem to load the variables from Moodle eventhough I have included the config.php file of moodle.

    Here’s my moodle and CI directory structure:
    <root>/moodle
    <root>/CI stuffs

    I tried using

    include ("<root>/moodle/config.php");

    and called $_SESSION[’$USER’] but CI can’t seem to load the variables. I tried creating a raw php file invoking the same config.php of moodle and I was able to retrieve the $_SESSION[’$USER’] with success.

    I think CI prevents something in the config.php of Moodle, but I’m not really sure.

    I’ll keep working on it and I’ll keep you posted if ever I find a workaround on this… I hope!

    Anyhow, any suggestions from the community will be greatly appreciated.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases