router.php:
<?php class Router{ protected $baseURL; protected $parsedURL; protected $modelpath; protected $id; public $model; public function __construct(){ //Ustawienie ścieżki do modeli $this->baseURL = "/inc/models/"; return $this->baseURL; } public function _parseURL($model){ //Zapisanie tablicy z podzielonym adresem URL $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php'; $this->id = $this->parsedURL[2]; $this->model = $this->parsedURL[2]; return $this->id; return $this->modelpath; return $this->model; //Próba odzewu } else{ $this->id = null; $this->model = $this->parsedURL[2]; return $this->id; return $this->modelpath; return $this->model; //Próba odzewu } } else{ //header("Location:./index.php"); } } public function _setRoute($model, $id){ try{ if(file_exist($this->modelpath)){ if($id == null){ include $this->modelpath; } else{ include $this->modelpath.'?nid=' . $id; } } else{ return false; } } catch(Exception $e){ } } } ?>
Testowy plik model dla news:
<?php ?>
htaccess:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
No i wywolanie tego wszystkiego z linku http://testowyserwer.serwer.pl/news
<?php function __autoload($classname){ } $router = new Router(); $router->_parseURL($_SERVER["REQUEST_URI"]); $router->_setRoute($model, $id); ?>
Po załadowaniu linku powyżej pokazuje się biała strona, nie wywołuje echo z news.php, ani z router.php