Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. require_once("database\adapters\PDO\Database.bootstrap.php");
  2. class App {
  3. protected $_controller = 'Welcome';
  4. protected $_method = 'index';
  5. protected $_params = [];
  6. protected $_model = 'Welcome';
  7.  
  8. public function __construct(){
  9. $url = $this->parseURL();
  10. //This works because I put the rewrite rules in IIS;
  11. //Our RewriteRule in IIS (or Apache) is ^(.+)$ This is any character saved to a variable.
  12. //The new location is index.php?url=$1 [QSA, L]. This will look a little different after you import it into IIS.
  13.  
  14. if (file_exists('app\controllers\' . $url[0] . '.controller.php')){
  15. $this->_controller = $url[0];
  16. $this->_model = $url[0];
  17. unset($url[0]); //Unset removes that element from the array;
  18. //var_dump($url);
  19. }
  20.  
  21. //Get the controller and model. All done by convention over configuration;
  22. require_once 'app\controllers\' . $this->_controller . '.controller.php';
  23. require_once 'app\models\Parent.model.php';
  24.  
  25. //get a new Database object from the bootstrap;
  26. $_DB = new DatabaseBootstrap();
  27.  
  28. $this->_controller = $this->_controller . "Controller";
  29.  
  30. $this->_model = new ParentModel($_DB->getAdapter());
  31. $this->_controller = new $this->_controller($this->_model);
  32.  
  33. //This checks to see if our method from the url exists;
  34. //Your querystring will look like this - http://server/virtualdirectory/controller/action/variables1/variable2.....
  35.  
  36. if(isset($url[1])){
  37. if(method_exists($this->_controller,$url[1])){
  38. $this->_method = $url[1];
  39. unset($url[1]);
  40. }
  41. }
  42.  
  43. $this->_params = $url ? array_values($url) : [];
  44.  
  45. //This calls your controller and your method and sends over your array of parameters
  46. call_user_func_array([$this->_controller, $this->_method],$this->_params)
  47. }
  48.  
  49. public function parseURL(){
  50. if(isset($_GET['url'])){
  51. return $url = explode('/',filter_var(rtrim($_GET['url'],'/'),FILTER_SANITIZE_URL));
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement