Skip to content

Commit

Permalink
Master Controller Improvements
Browse files Browse the repository at this point in the history
Changed behavior of `beforeroute.php` and `afterroute.php`. These files are now only loaded when that specific module is loaded. The old functionality can be achieved by using `beforeroute_global.php` and `afterroute_global.php`.
Added new f3 variable called `$method` which tells you which method was called in the module controller.
  • Loading branch information
GrumpyCrouton committed Sep 15, 2020
1 parent 064082e commit 42b109c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/controller.php
Expand Up @@ -5,15 +5,21 @@ class Controller {
protected $f3;

function beforeroute(){
//echo 'Before routing - ';
foreach (glob($this->f3->get('UI')."*/beforeroute.php") as $filename) {
$ui = $this->f3->get('UI');
if(file_exists($file = "{$ui}$module/beforeroute.php")) {
include $file;
}
foreach (glob("{$ui}*/beforeroute_global.php") as $filename) {
include $filename;
}
}

function afterroute(){
//echo '- After routing';
foreach (glob($this->f3->get('UI')."*/afterroute.php") as $filename) {
$ui = $this->f3->get('UI');
if(file_exists($file = "{$ui}$module/afterroute.php")) {
include $file;
}
foreach (glob($this->f3->get('UI')."*/afterroute_global.php") as $filename) {
include $filename;
}
}
Expand All @@ -28,6 +34,9 @@ function __construct() {
$module = $this->f3->get("PARAMS.module");
$this->f3->module = $module ? $module : $this->f3->get("defaultModule");

$method = $this->f3->get("PARAMS.method");
$this->f3->method = !empty($method) ? $method : $this->f3->VERB;

}

public function render($content, $template = 'default') {
Expand Down

0 comments on commit 42b109c

Please sign in to comment.