Include a file external to Codeigniter

Asked

Viewed 624 times

3

I am trying to make an integration between a system developed in Codeigniter(CI) with Moodle and I need to include in the CI a file from the Moodle library, to recover some data.

However I am not able to do the inclusion of the arquvio in the IC, to work with it within the controllers. File inclusion works perfectly in CI index.php, but I can’t use its variables inside the controllers

Remembering that my IC is inside a folder of Moodle, ie it would be a module of this system.

Someone has the knowledge to achieve this integration?

The structure is like this: inserir a descrição da imagem aqui I want to include inside the CI the parameter.php file and use its variables in the controllers

File parameters.php

<?php   
    unset($CFG);
    global $CFG;
    $CFG = new stdClass();
    require_once(dirname(__FILE__) . '/lib/setup.php');

lib/setup.php can be viewed here:

https://github.com/moodle/moodle/blob/master/lib/setup.php

  • Did you ask her where? Have you tried looking at load.php, to load the model automatically?

  • Not a model, Moodle is a CMS

  • What is the contents of the file?

  • It is a variable that contains an object

  • Put the content, there are countless ways to create the variables, can be in array, can be in anything. Session only fails with the included file or fails without?

  • Dude, this file is like an autoload of Moodle, it imports several classes into this file, and these files have several other uploads. Which makes it impossible to put all the files here, but basically the.php parameter is what I have now put in Description.

Show 1 more comment

1 answer

1

You need to insert Moodle in the "application/third_party" folder, after that in the "Libraries" insert a file "Moddle.php"

<?php defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH.'/third_party/moodle/index.php';

class CIMoodle extends Moodle {
    public function __construct()
    {
        parent::__construct();
    }

    // Outros métodos aqui.
}

After that in the controller only use one

$this->load->library("cimoodle");
$todo = $this->cimoodle->algummetodo();
  • I can not do this way, because Moodle is the main system, Codeigniter would be a module for it, with an old application. In the case I basically need to take the Moodle session and use it in Codeigniter, so I’m trying to include the file with the Moodle sessions

  • Sorry then, I had misunderstood.

  • I think you can still do something similar, ignore the "third_party" and instate in the Construct of a lib the Moodle session, then just go recovering the data within the lib methods.

  • I will try this way Vinicius, and follow this path. Let’s see where I will arrive... Thank you

  • Up to this point it worked, the problem is that if I start the codeigniter session it closes the active session of Moodle.

  • try to capture the section of the Moodle instead of replacing it in the codeigniter, assign the new session within it.

  • but that’s exactly what I want to do, but I haven’t figured out how yet, because to recover the session I need to do this include

  • You do not have to include, sessions are not stored by the system but by the server, so in any Sv directory you can access a session of the X or Y system.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.