在我的 slim 框架 REST API 中,有一个带有 POST 方法的函数“loadData”。 该函数包含一个名为“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);
}
所以上面提到的代码是我想做的事情。请帮助重定向。
最佳答案
注意:无法访问其他文件夹中的任何 Controller ,并且不允许以这种方式访问脚本。
所以route.php
中必须设置路由才能使用路由路径访问该功能。
它可以定义如下:-
$captcha_url = "http://your_api_url/index.php/[route defined in route.php]/"
例如:- 在 route.php
中,路由定义为:-
$route['nlpgen/nlpimg/(.+)']='xyz/callABC/$1';
然后访问 Controller :-
$captcha_url = "http://your_api_url/index.php/nlpgen/nlpimg/"
现在您可以使用CURL
来访问外部URL。
关于php - 如何从 slim Rest API 函数重定向到 codeigniter Controller 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48341250/