![]() |
redirect not working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: redirect not working (/showthread.php?tid=92270) |
redirect not working - 4usol - 01-03-2025 Hi i try to run a function from a library wich returns a redirect. It failed, the redirect not fired, i dont know what i do wrong. Here is the situation in basecontroller i add my library on initController Code: public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) also in basecontroller i defined these function Code: public function initPage(){ In the library i've two functions - The one i've called in the base-controller Code: public function my_lib_function() and the function for handle and doing the redirect himself Code: public function my_redirect($view='defaultview') Notice: "Errors" is a controller in the main Controllers-Folder. Here are the routes for them Code: $routes->get('errors/(:any)', 'Errors::code/$1'); So the result is that the redirect from the POS1 dont run. Nothing happens. If i add the "die(..)" statements the DIE1 print out, but not more. If i comment the DIE1 out, the code goes on... Why the redirect dont work? RE: redirect not working - InsiteFX - 01-03-2025 For one routes with (:any) need to be the last routes in the route list or they will not work. RE: redirect not working - 4usol - 01-03-2025 (01-03-2025, 11:25 PM)InsiteFX Wrote: For one routes with (:any) need to be the last routes in the route list or they will not work.Thats a interesting info, it it for a "any" rout for the same controller, so any routes for the same controller must defined at least of each? I reduce it to only Code: "$routes->get('errors/(:any)', 'Errors::show/$1'); " But i think this is not the problem, if i put the url directly the route works... In touch with my situation i find another point wich produces a same kind of problem, may here its easier to find the problem. If i change the route for 404 errors in Routes.php Code: $routes->set404Override(function() The "header(..." works only if i add a "die(" command, if there is no "die" the header wont work. - Why? The play arounds with "redirect()" - failed all - Why? Also if i try this Code: return redirect()->to('errors/error_404', null, 'refresh'); or Code: return redirect()->back()->withHeaders(); on "if ($override instanceof Closure) {955 echo $override($e->getMessage());" For me it only works by using the core "header(...)" function and "die()", i want to understand why the "redirect" dont work, so i hope someone can find the missing info:-) |