Also... ich habe jetzt eine Router-Klasse die so aussieht:
Code:
<?php
class Router {
private $url;
private $classname;
private $functionname;
function __construct($url){
$this->getURL($url);
$this->getclassname();
$this->getfunction();
}
//trim(strtolower($_SERVER['REQUEST_URI']), '/');
public function showURL() {
echo $this->url;
}
public function showclass() {
echo $this->classname;
}
public function showfunction() {
echo $this->functionname;
}
private function getfunction() {
$precna = explode('/', $this->url);
$this->functionname = $precna[1];
}
private function getURL($url){
$this->url = $url;
return $this->trimURL();
}
private function getclassname() {
$precna = explode('/', $this->url);
$this->classname = $precna[0];
}
private function trimURL(){
return $this->url = trim(strtolower($this->url),'/');
}
public function run(){
if(class_exists($this->classname)){
$controller = new $this->classname;
if(method_exists($controller, $this->functionname)){
$fn = $this->functionname;
$controller->$fn.'()';
} else {
echo "function not found";
}
} else {
$controller = new Controller();
$controller->display();
}
}
}
?>
Aber ich komme bei der fettmarkierten Zeile nicht weiter...
und ich habe eine idex die so aussieht:
Code:
<?php
include('classes/controller.php');
include('classes/model.php');
include('classes/view.php');
include('core/router.php');
$url = $_SERVER['REQUEST_URI'];
$router = new Router($url);
$router->run();
?>
und die default.php die aufgerufen wird wenn kein Controller gefunden werden konnte sieht so aus:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="templates/style.css">
<title>Test</title>
</head>
<body>
<header>
<h1>Test</h1>
<hr />
</header>
<nav>
<form action"controller/login" method="post">
<label>Benutzername</label>
<input type="text" name="bname">
<label>Passwort</label>
<input type="password" name="bpassw">
<button type="submit">login</button>
</form>
</nav>
<section></section>
<footer></footer>
</body>
</html>
Ich weiss nicht wie ich den String in $classname hinter den "new" Aufruf bekomme und dann das Selbe mit der Funktion hinter dem ->
und was ich in das action von dem Formular schreiben muss. Vor allem weiss ich noch nicht wie ich das hinbekomme dass das was in action steht in der url landet... bitte um hilfe :)