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)
{
$this->mylib = new MyLib();
}
also in basecontroller i defined these function
Code:
public function initPage(){
$this->myLib = new MyLib(); //Why need to create a new instance and dont use the instance from initController - my tries failed - is it possible?
$this->myLib->my_lib_function();
}
In the library i've two functions
- The one i've called in the base-controller
Code:
public function my_lib_function()
{
$this->my_redirect('viewname'); //POS1
die("die after my_redirect"); //DIE1
//go on...
}
and the function for handle and doing the redirect himself
Code:
public function my_redirect($view='defaultview')
{
//header('Location: /Errors/'.$view); //Here a redirect fired but thats not the way in codeigniter4 so i won't use it
return redirect()->to('Errors::'.$view); //Play around with "return" or without - has no effect
}
Notice: "Errors" is a controller in the main Controllers-Folder.
Here are the routes for them
Code:
$routes->get('errors/(:any)', 'Errors::code/$1');
$routes->get('errors', 'Errors::index');
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?