3

I have one directory "Store" which is outside Application directory of CodeIgniter. Here I need to call one controller method from "Store" directory.

Is is possible to call controller method from directory which is outside Application Directory?

Thanks.

aanandj23
  • 31
  • 2
  • 4
  • 1
    Why is it outside the application directory? Why not just move the controller to the normal location? – Laurence Sep 04 '12 at 06:13

1 Answers1

1

As far as I know, using $this->load (Loader class i.e.), you can't. Even if you directly include like in the following way:

application/controllers/test.php

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

require('/absolute/path/to/dummy.php');

class Test extends CI_Controller {
    public function handle(){
        $d = new Dummy();
        $d->handle();
    }
}

dummy.php

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

class Dummy extends CI_Controller {
    public function handle(){
        // do something here
    }
}

It(including) won't work because you specifically disallowed direct access! But, if you don't disallow that, then, your controller code is prone to exploitation, and you won't have a problem.


So, one way to do it if the other controller part of another codeigniter project is, using command line.

dummy.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access 

class Test extends CI_Controller {
    public function handle(){
        $d = new Dummy();
        $d->handle();
    }
}

application/controllers/test.php

public function handle(){
    exec("cd /absolute/path/to/dummyproject; php index.php dummy handle;");
}

You can further find out how to pass command line arguments too.

Prasanth
  • 5,230
  • 2
  • 29
  • 61