通过外部脚本调用函数codeigniter脚本

时间:2016-09-26 21:11:47

标签: php codeigniter

我的情况是:

  • 我有一个使用codeigniter工作的项目
  • 控制器内部我需要调用php脚本的功能
  • 我有其他脚本运行后台,当它获取数据时,发送到codeigniter控制器

第一行:

include('/opt/lampp/htdocs/myproject/application/controllers/myFile.php');

此脚本正在运行后台程序。

function procmsg($topic,$msg){
    //do something...
    //my_function() is a function in the myFile.php script
    my_function(true, $userGtwy, $passwdGtwy, $node_id, $idGateway, $value, $rssi);
}

myFile.php

此脚本的第一行:

require(APPPATH.'/libraries/REST_Controller.php');
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

功能:

public function my_function($flag=false, $usr, $pass, $node, $gateway, $val, $freq){}

当我运行我的第一个脚本时,我得到:

PHP Notice:  Use of undefined constant APPPATH - assumed 'APPPATH' in /opt/lampp/htdocs/myproject/application/controllers/myFile.php on line 3
PHP Warning:  require(APPPATH/libraries/REST_Controller.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/myproject/application/controllers/myFile.php on line 3
PHP Fatal error:  require(): Failed opening required 'APPPATH/libraries/REST_Controller.php' (include_path='.:/usr/share/php') in /opt/lampp/htdocs/myproject/application/controllers/myFile.php on line 3

并且,如果我评论这一行:

require(APPPATH.'/libraries/REST_Controller.php');

我得到:  No direct script access allowed 我需要这个库,我需要使用我的脚本访问,请帮助我!

我发现了这个:Access Codeigniter functions from external script 但我不明白......

我的问题,我可以这样做吗?还是不可能?

0 个答案:

没有答案