(01-29-2025, 11:50 PM)InsiteFX Wrote: This works in a html view may work in a library not sure or tested.
PHP Code:
// Try to use a named route. |name
$routes->get('{locale}/blog', 'Blog::index', ['as' => 'blog']);
// then try the redirect
return redirect()->to('blog');
No, this redirect does not work from the Library class.
I tried to use header() and it works only with exit()
PHP Code:
header('Location: '. base_url($redirect_url));
exit();
I created, as a temporary solution, a function in helper:
PHP Code:
function redirect_to_page($page) {
header('Location: '. $page);
exit();
}
I am using it in the library class:
PHP Code:
redirect_to_page(base_url($redirect_url));
It would be better to use CodeIgniter methods, but so far I could not find a solution.