Redirect in CI4

Redirect with a Flash Message

To pass data (like success or error messages) during a redirect, you can use session flashdata.

Example:

Set flashdata in the controller before redirecting:

Retrieve flashdata in the redirected page:

 

Redirect with POST/GET Data

To pass query parameters or data, append them to the redirect URL.

Retrieve input in the redirected controller:

Conditional Redirect

You can dynamically redirect users based on conditions.

Use redirect() Helper Function

The redirect() function is a global helper and can be used without $this or BaseController.

Example:

 

Leave a Reply

Your email address will not be published. Required fields are marked *