CI4框架controller如何相互调用
php吧
全部回复
仅看楼主
level 1
尕御摩羯 楼主
如图,我使用composer创建了两个ci4框架的项目,项目A接口使用$_POST接收数据
现在我在开发项目B的时候想要调用项目A的接口,我看了ci4的文档,使用了curlRequest进行调用,代码如下图所示
现在的问题是,可以调通接口,但是参数没有传过去,请问各位大佬如何解决
2022年04月08日 11点04分 1
level 1
尕御摩羯 楼主
顶一下
2022年04月08日 14点04分 2
level 9
返回啥了?给一下。$response
2022年04月10日 00点04分 4
发在下面了,麻烦大佬看一下
2022年04月10日 08点04分
level 1
尕御摩羯 楼主
CodeIgniter\HTTP\Response Object( [reason:protected] => OK [statusCode:protected] => 200 [pretend:protected] => [protocolVersion:protected] => 1.1 [validProtocolVersions:protected] => Array ( [0] => 1.0 [1] => 1.1 [2] => 2.0 )
[body:protected] => {"state":1,"data":[{"user_id":"1","vuid":"","username":"333","nickname":"qqq","realname":"jin","phone":"
13313656661
","password":"222","photo":"","created_at":"2022-04-07 11:54:03","updated_at":"2022-04-07 11:54:03"},{"user_id":"2","vuid":"","username":"a333","nickname":"qqq111111111111111","realname":"jin","phone":"
13313656661
","password":"22233322212","photo":"","created_at":"2022-04-07 15:03:45","updated_at":"2022-04-07 15:03:45"},{"user_id":"3","vuid":"","username":"a333","nickname":"qqq111111111111111","realname":"jin","phone":"
13313656661
","password":"22233322212","photo":"","created_at":"2022-04-07 15:16:51","updated_at":"2022-04-07 15:16:51"},{"user_id":"4","vuid":"164931637860","username":"a333","nickname":"qqq111111111111111","realname":"jin","phone":"
13313656661
","password":"22233322212","photo":"","created_at":"2022-04-07 15:26:18","updated_at":"2022-04-07 15:26:18"},{"user_id":"5","vuid":"164932179893","username":"a3334","nickname":"qqq111111111111111","realname":"jin","phone":"
13313656662
","password":"dfe382df655bc8463f48d4edfb8bf2b5","photo":"","created_at":"2022-04-07 16:56:38","updated_at":"2022-04-07 16:56:38"}]} [headers:protected] => Array ( [Cache-control] => CodeIgniter\HTTP\Header Object ( [name:protected] => Cache-control [value:protected] => Array ( [0] => no-store [1] => max-age=0 [2] => no-cache )
)
[Content-Type] => CodeIgniter\HTTP\Header Object ( [name:protected] => Content-Type [value:protected] => text/html; charset=utf-8 )
[Date] => CodeIgniter\HTTP\Header Object ( [name:protected] => Date [value:protected] => Sun, 10 Apr 2022 08:08:50 GMT )
[Server] => CodeIgniter\HTTP\Header Object ( [name:protected] => Server [value:protected] => Apache/2.4.46 (Win64) PHP/7.3.21 )
[X-Powered-By] => CodeIgniter\HTTP\Header Object ( [name:protected] => X-Powered-By [value:protected] => PHP/7.3.21 )
[Access-Control-Allow-Origin] => CodeIgniter\HTTP\Header Object ( [name:protected] => Access-Control-Allow-Origin [value:protected] => * )
[Content-Length] => CodeIgniter\HTTP\Header Object ( [name:protected] => Content-Length [value:protected] => 1147 )
)
[headerMap:protected] => Array ( [cache-control] => Cache-control [content-type] => Content-Type [date] => Date [server] => Server [x-powered-by] => X-Powered-By [access-control-allow-origin] => Access-Control-Allow-Origin [content-length] => Content-Length )
[CSPEnabled:protected] => [CSP] => CodeIgniter\HTTP\ContentSecurityPolicy Object ( [baseURI:protected] => [childSrc:protected] => self [connectSrc:protected] => self [defaultSrc:protected] => [fontSrc:protected] => [formAction:protected] => self [frameAncestors:protected] => [frameSrc:protected] => [imageSrc:protected] => self [mediaSrc:protected] => [objectSrc:protected] => self [pluginTypes:protected] => [reportURI:protected] => [sandbox:protected] => [scriptSrc:protected] => self [styleSrc:protected] => self [manifestSrc:protected] => [upgradeInsecureRequests:protected] => [reportOnly:protected] => [validSources:protected] => Array ( [0] => self [1] => none [2] => unsafe-inline [3] => unsafe-eval )
[nonces:protected] => Array ( )
[tempHeaders:protected] => Array ( )
[reportOnlyHeaders:protected] => Array ( )
)
[cookieStore:protected] => CodeIgniter\Cookie\CookieStore Object ( [cookies:protected] => Array ( )
)
[cookiePrefix:protected] => [cookieDomain:protected] => [cookiePath:protected] => / [cookieSecure:protected] => [cookieHTTPOnly:protected] => 1 [cookieSameSite:protected] => Lax [cookies:protected] => Array ( )
[bodyFormat:protected] => html)
2022年04月10日 08点04分 6
body:protect里的应该就是你想要的data数组吧。看情况,值是返回了。估计是要调$response object的方法去读。你的框架我没用过,不过这些东西都是相通的。不知道方法的话,可以get method一下。
2022年04月10日 22点04分
@暗夜公爵Char 我是可以读出来的,用$body = $response->getBody(); $body = json_decode($body, true);,但是这不是我要的返回值,因为这里返回的是不传参数的结果,返回了数据库所有的数据。然而我传了参数,应该返回用户不存在的。也就是说参数没发过去,这是我不理解的地方。。
2022年04月11日 01点04分
@尕御摩羯 那就不是传值的问题啊。你应该去查那个就收参数,处理参数的方法。
2022年04月11日 03点04分
@暗夜公爵Char 谢谢大佬,我看文档搞定了
2022年04月11日 09点04分
1