Blank page after redirection

Hello everybody,
I’ve follow a tutorial from Codecourse on youtube for building an authentification form in Slim3. I’m trying now to implement multi-language. However, I’ve got a blank page after validation of my form. I don’t know what to do, or where to look at… :-/

I’ve made my routes like that:

$this->get(‘/fr/login’, AuthController::class . ‘:fr_getLogin’)->setName(‘fr_web_getLogin’);
$this->post(‘/fr/login’, AuthController::class . ‘:fr_postLogin’)->setName(‘fr_web_postLogin’);
$this->get(‘/en/login’, AuthController::class . ‘:en_getLogin’)->setName(‘en_web_getLogin’);
$this->post(‘/en/login’, AuthController::class . ‘:en_postLogin’)->setName(‘en_web_postLogin’);

And in AuthController.php, I’ve made a function to recognize language with each route name :

use Respect\Validation\Validator as v;

class AuthController extends Controller{
protected $param;

public function callMainRoute($routeName, $request, $response){
$controller = $this->param[‘controllerName’] = substr($routeName,3);
$_SESSION[‘lang’] = $this->param[‘lang’] = substr($routeName, 0, 2);
self::$controller($request, $response);
}

//and my post functions
public function fr_postLogin($request, $response){self:: callMainRoute(FUNCTION,$request, $response);}
public function en_postLogin($request, $response){self:: callMainRoute(FUNCTION,$request, $response);}
public function postLogin($request, $response){
//Respect validation
$validation = $this->validator->validate($request,[
‘email’ => v::notEmpty()->email(),
‘password’ => v::notEmpty(),
]);
if($validation->failed()){
//this is what doesn’ work and return a blank page…
return $response->withRedirect($this->router->pathFor($_SESSION[‘lang’].‘_web_getLogin’));
}
//…suite of script authentification
}

Thank you a lot for any help !

I’m on my phone so can’t easily write code examples, but I would suggest a different approach.

Firstly, make the language a parameter in your routes so that you don’t have to repeat yourself so much.

Add some middleware that looks at the language and adds an attribute to the request that you can retrieve later to check what language was detected.

Use the same validator and controller action for every log-in route, because it’s the same thing. You’d be better handling the localised messaging in a messages file, rather than in your application logic.

Doesn’t necessarily help with your particular problem (sorry!) but I think that would be easier for you to work with. :+1:

Good luck

thank you for you help!
Well, I’ve tried to make a function so that I don’t repeat my code too much, but I’m sure there is a better approach as you said.

Could you write me an exemple for that, because I don’t understand how this will reduce recurrences in my code ? Do you think about things like : $this->get(’/{fr}/login’… ?
With 2 languages with get and post, You really need 4 routes, don’t you ?

Well, I dont see how I coud use a middleware like that. When I tried a language middleware, I need to reload the page to get the right language as if the middleware where getting the language after the loading page… Again if you have a piece of code, it would be so nice !

Mhh that’s a bit abstract for me… :sweat_smile: where could I see some code with this logic you described ?
Thank you once again !

Hello, I’ve succeeded in applying your first advise (“make the language a parameter in my routes”) and I change everything after that. And I don’t know why but, I don’t have an error any more (and a blank page) after that ! So thank you.

But your 3rd advice still intrigates me (“Use the same validator and controller action for every log-in route”)… Could you explain it to me (with an exemple in possible) ? I’m looking for translating my Respect/validation error messages, and maybe, it could really help ! (it seems very tricky to translate them)
Thank you again !