I'm using CodeIgniter 4.
I have 2 controllers:
<?php namespace App\Controllers;
class Dashboard extends BaseController{
public function index(){
//pre-condition - logged
if(!$this->session->has("email")){
//go to login
return redirect()->route("login");
}
return view("dashboard");
}
}
//---------------------
class Profile extends BaseController{...}
In those 2 controllers I have some methods which represent routes /dashboard
, /profile
, /profile/settings
, etc.
In every method I have the same pre-codition if(...){ return redirect()->route("login"); }
.
This pre-condition check if user is logged.
How I can set this pre-condition to be at all methods from controller, without rewriting in every method from Dashboard
and Profile
?