要在 CodeIgniter 4 取得 post 或 get 的資訊,可以透過 getPost() 和 getGet() 取得,像是:
$name = $this->request->getPost('name'); $user = $this->request->getGet('user');
也可以透過 IncomingRequest 幫我們取得,像是:
use CodeIgniter\HTTP\IncomingRequest; $request = service('request'); $request->getGet('foo'); $request->getPost('foo');
也可以透過 getVar() 直接取得變數或透過 getJSON() 取得 AJAX call 的內容:
// Retrieve from $_REQUEST which should include // both $_GET and $_POST contents $request->getVar('foo'); // Retrieve JSON from AJAX calls $request->getJSON();