gpt4 book ai didi

codeigniter - 在 Application 目录外调用 CodeIgniter 的 Controller 方法

转载 作者:行者123 更新时间:2023-12-02 03:56:49 25 4
gpt4 key购买 nike

我有一个目录“Store”,它位于 CodeIgniter 的应用程序目录之外。这里我需要从“Store”目录调用一个 Controller 方法。

是否可以从应用程序目录之外的目录调用 Controller 方法?

谢谢。

最佳答案

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

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
}
}

它(包括)不会工作,因为您特别禁止直接访问!但是,如果您不禁止,那么,您的 Controller 代码很容易被利用你不会有问题


因此,如果另一个 codeigniter 项目的另一个 Controller 部分是使用命令行,则可以采用一种方法。

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

您还可以进一步了解如何传递命令行参数。

关于codeigniter - 在 Application 目录外调用 CodeIgniter 的 Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12257538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com