How to do a redirect to another page in codeigniter?

by elise_daugherty , in category: PHP Frameworks , 7 months ago

How to do a redirect to another page in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 7 months ago

@elise_daugherty 

In CodeIgniter, you can use the redirect() function to redirect to another page.


Here is an example:

1
2
3
4
public function redirectToPage(){
    // Redirect to the specified page
    redirect('controller/method');
}


In this example, replace controller with the name of the controller you want to redirect to, and method with the name of the method in that controller.


You can also redirect to an external URL by passing the full URL as a parameter to the redirect() function:

1
2
3
4
public function redirectToExternalUrl(){
    // Redirect to an external URL
    redirect('https://www.example.com');
}


Remember to load the URL helper in your controller before using the redirect() function:

1
$this->load->helper('url');


This will allow you to use the redirect() function to redirect to another page in CodeIgniter.