在应用程序目录外调用CodeIgniter的Controller方法 [英] Call Controller method of CodeIgniter outside Application directory

查看:55
本文介绍了在应用程序目录外调用CodeIgniter的Controller方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录 Store,它在CodeIgniter的Application目录之外。在这里
我需要从 Store目录中调用一个控制器方法。

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?

谢谢。

推荐答案

据我所知,使用 $ this-> load (Loader类即),您不能。即使您直接通过以下方式添加:

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.

因此,如果另一个codeigniter项目的另一个控制器部分是使用命令行,则是一种方法。

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();
    }
}

应用程序/控制器/测试。 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.

这篇关于在应用程序目录外调用CodeIgniter的Controller方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆