I would like to make a redirect from Library class in CI4. It does not work. I am changing the code from CI3 to CI4 and after I read a lot of topics regarding redirect I could not find an example for my case.
In CI3 it was easy to use redirect():
PHP Code:
redirect(base_url($redirect_url), 'location', 301);
I used these redirects and it does not work:
PHP Code:
return redirect()->to(base_url($redirect_url));
return redirect()->to($redirect_url);
I am getting an error if I use redirect()->route():
The route for URL cannot be found.
PHP Code:
return redirect()->route($redirect_url,[], 301);
This is not from Controller. I need a redirect to a different page from Library Class, which is located in APP\Libraries\LibraryFolder\LibraryClass.php
Please let me know if there is a way to make it work.