如何从 slim Rest API 函数重定向到 codeigniter 控制器函数?
how to get redirected from slim Rest API function to codeigniter controller function?
在我的 slim 框架 REST API 中,有一个函数 say "loadData" 和 POST 方法。
此函数包含一个名为 "options" 的数组。
loadData函数的路径是:
c:\xampp\htdocs\cmp_mgmt\app\v1\controllers\xyz.php
我想调用一个名为 "callABC($option)" 的 codeigniter 函数。此函数在文件路径
c:\xampp\htdocs\mgmt\application\controllers\Ad.php
.
所以我想要的是:
loadData(Request $request, Response $response, $args)
{
$options_arr = $request->getParsedBody();
$call = c:\xampp\htdocs\mgmt\application\controllers\Ad\callABC($options_arr);
return $response->withJson($call,200);
}
所以上面提到的代码是我想做的。请帮助重定向。
注意:无法访问其他文件夹中的任何控制器,并且不允许通过这种方式访问脚本。
所以必须在 route.php
中设置路由,然后才能使用路由路径访问该功能。
它可以定义如下:-
$captcha_url = "http://your_api_url/index.php/[route defined in route.php]/"
例如:- 在 route.php
中,路由定义为:-
$route['nlpgen/nlpimg/(.+)']='xyz/callABC/';
然后访问控制器:-
$captcha_url = "http://your_api_url/index.php/nlpgen/nlpimg/"
现在您可以使用 CURL
访问外部 URL。
在我的 slim 框架 REST API 中,有一个函数 say "loadData" 和 POST 方法。 此函数包含一个名为 "options" 的数组。 loadData函数的路径是:
c:\xampp\htdocs\cmp_mgmt\app\v1\controllers\xyz.php
我想调用一个名为 "callABC($option)" 的 codeigniter 函数。此函数在文件路径
c:\xampp\htdocs\mgmt\application\controllers\Ad.php
.
所以我想要的是:
loadData(Request $request, Response $response, $args)
{
$options_arr = $request->getParsedBody();
$call = c:\xampp\htdocs\mgmt\application\controllers\Ad\callABC($options_arr);
return $response->withJson($call,200);
}
所以上面提到的代码是我想做的。请帮助重定向。
注意:无法访问其他文件夹中的任何控制器,并且不允许通过这种方式访问脚本。
所以必须在 route.php
中设置路由,然后才能使用路由路径访问该功能。
它可以定义如下:-
$captcha_url = "http://your_api_url/index.php/[route defined in route.php]/"
例如:- 在 route.php
中,路由定义为:-
$route['nlpgen/nlpimg/(.+)']='xyz/callABC/';
然后访问控制器:-
$captcha_url = "http://your_api_url/index.php/nlpgen/nlpimg/"
现在您可以使用 CURL
访问外部 URL。