Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_once("database\adapters\PDO\Database.bootstrap.php");
- class App {
- protected $_controller = 'Welcome';
- protected $_method = 'index';
- protected $_params = [];
- protected $_model = 'Welcome';
- public function __construct(){
- $url = $this->parseURL();
- //This works because I put the rewrite rules in IIS;
- //Our RewriteRule in IIS (or Apache) is ^(.+)$ This is any character saved to a variable.
- //The new location is index.php?url=$1 [QSA, L]. This will look a little different after you import it into IIS.
- if (file_exists('app\controllers\' . $url[0] . '.controller.php')){
- $this->_controller = $url[0];
- $this->_model = $url[0];
- unset($url[0]); //Unset removes that element from the array;
- //var_dump($url);
- }
- //Get the controller and model. All done by convention over configuration;
- require_once 'app\controllers\' . $this->_controller . '.controller.php';
- require_once 'app\models\Parent.model.php';
- //get a new Database object from the bootstrap;
- $_DB = new DatabaseBootstrap();
- $this->_controller = $this->_controller . "Controller";
- $this->_model = new ParentModel($_DB->getAdapter());
- $this->_controller = new $this->_controller($this->_model);
- //This checks to see if our method from the url exists;
- //Your querystring will look like this - http://server/virtualdirectory/controller/action/variables1/variable2.....
- if(isset($url[1])){
- if(method_exists($this->_controller,$url[1])){
- $this->_method = $url[1];
- unset($url[1]);
- }
- }
- $this->_params = $url ? array_values($url) : [];
- //This calls your controller and your method and sends over your array of parameters
- call_user_func_array([$this->_controller, $this->_method],$this->_params)
- }
- public function parseURL(){
- if(isset($_GET['url'])){
- return $url = explode('/',filter_var(rtrim($_GET['url'],'/'),FILTER_SANITIZE_URL));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement