I have a project that uses the MVCish pattern.
I have a bootstrap file that takes info from GET to find out what controller to load up and the method from it but I'm stuck on the part on how can I pass additional GET parameters as parameters to the method being called.
My current bootstrap index.php file looks like this:
<?php
// sessions
session_start();
// config
require('common/Config.php');
// database
require('common/Db.php');
$_db = new Db();
// web
require('common/Web.php');
// main
require('cnt/Main.php');
$main = new Main($_db);
// current controller/view
$r = (isset($_GET['r']) && $_GET['r'] != '') ? $_GET['r'] : 'site/index';
// check auth
if($r != 'auth/index' && $r != 'auth/login'){
if(isset($_SESSION['id'], $_SESSION['token']) && $_SESSION['id'] != null && $_SESSION['token'] != null){
if(!$main->validateAuth($_SESSION['id'], $_SESSION['token'])){
$main->redirect('auth/index');
}
} else {
$main->redirect('auth/index');
}
}
// render page
$ep = explode('/', $r); $cnt = ucfirst($ep[0]); $action = 'action'.ucfirst($ep[1]);
unset($_GET['r']);
if(!empty($_GET)){
// additional parameters
}
include_once('cnt/'.$cnt.'.php');
$class = new $cnt($_db);
$class->$action();
How can I achieve this?