I'm running my own MVC structure and I've ran into an issue that I can't figure out how to get around or fix. I've looked at various other questions like 1, 2, and many others which didn't quite help.
I have a table in the database that returns a user's information, if the information isn't found then redirect them to a page to force them to submit the data.
I created a Authenticated class which extends the controller (contains the redirect method):
abstract class Authenticated extends \Core\Controller {
protected function before() {
$this->requirePersonality();
}
protected function requirePersonality(){
if(!(new PlannerAuth())->getPersonality()){
$this->redirect('/app/personalization');
}
}
}
In my App Controller I've got:
class App extends Authenticated {
protected function before(){
parent::before();
}
public function personalizationAction(){
View::renderTemplate('App/personalization.html');
}
}
The before() method will run before any and every action method, so when I run any url in the application the following logic happens:
Authentication before()
runs, redirects me to /app/personalization, once there, it checks the current before()
, which reruns the authentication before()
method again, and on and on.. creating an infinite loop.
I've also got an after()
method, which will run after all of the methods, but that won't work since it won't force the user onto the personalization page.
This will only happen when I run any method in the App controller, I could have the personalizationAction
in another controller, but that's not what I need.