What are the built-in CodeIgniter 4 Response methods?
Answer
The Response object in CodeIgniter 4 provides a clean API for building HTTP responses. Access via $this->response in controllers. Set body: $this->response->setBody($html). Set status code: $this->response->setStatusCode(404). Set content type: $this->response->setContentType("application/json"). Set headers: $this->response->setHeader("X-Custom", "value"). Return JSON: return $this->response->setJSON($data) — automatically sets the content type and encodes the array. Return HTML view (shorthand): return view("viewname", $data). Redirect: return redirect()->to("url") or redirect()->route("routename"). Set cookies: $this->response->setCookie("name", "value", 3600). Download: $this->response->download("filename.pdf", $data).
Previous
What is the Config system in CodeIgniter 4?
Next
What is the Request object in CodeIgniter 4?