Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter 4 redirect function not working

After logout, I tried to redirect for the home page. I tried to few ways, but not redirected.

class User extends BaseController
{
    public function __construct()
    {
        helper('url');
    }

for the logout function. I used three ways

redirect('/');

or

header("Location:".base_url());

or

route_to('/');
like image 254
Senthil Avatar asked Nov 05 '19 09:11

Senthil


People also ask

How to use redirect in codeigniter 4?

Redirect With Named Route To use named route, we have an option to use route(). //... public function addUser() { if ($this->request->getMethod() == "post") { // Save data here return redirect()->route("users"); // Calling name defined in 'as' in Routes.

How to redirect on same page in codeigniter 4?

“codeigniter redirect to same page” Code Answer's //The redirects functions accepts two parameters to execute the function first is 'Location Url' and second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".

How to redirect URL in codeigniter?

php class Redirect_controller extends CI_Controller { public function index() { /*Load the URL helper*/ $this->load->helper('url'); /*Redirect the user to some site*/ redirect('http://www.tutorialspoint.com'); } public function computer_graphics() { /*Load the URL helper*/ $this->load->helper('url'); redirect('http:// ...


1 Answers

as per CI 4

use

return redirect()->to('url'); 

if you are using route then use

return redirect()->route('named_route');
like image 95
Devsi Odedra Avatar answered Oct 21 '22 10:10

Devsi Odedra