Woutertjuh88
Terugkerende gebruiker
- Lid geworden
- 20 nov 2005
- Berichten
- 3.532
Op mijn site/applicatie gebruik ik .htaccess om van mijn linkjes naar classes/functions(+ soms nog een id die mee wordt gegeven.) te gaan in PHP.
www.domein.nl/Class/function/
Dit werkt prima!
Maar nu wil ik ook subdomeinen op de zelfde manier gaan gebruiken, dus:
www.[U]sub[/U].domein.nl/Class/function/
Helaas werkt dit niet en nu vraag ik me af waar mijn fout dan ligt, want de bestanden worden niet gevonden.
Ik host op dit moment bij Antagonist en heb Direct Admin tot mijn beschikking.
.htaccess
index.php
_autoload.php
voorbeeld van een classe
Begrijp je het niet, dan heb ik het vast verkeerd uitgelegd en leg ik het nog een keer uit als dit nodig is.
www.domein.nl/Class/function/
Dit werkt prima!
Maar nu wil ik ook subdomeinen op de zelfde manier gaan gebruiken, dus:
www.[U]sub[/U].domein.nl/Class/function/
Helaas werkt dit niet en nu vraag ik me af waar mijn fout dan ligt, want de bestanden worden niet gevonden.
Ik host op dit moment bij Antagonist en heb Direct Admin tot mijn beschikking.
.htaccess
PHP:
RewriteEngine On
RewriteRule ^(.*)/(.*)/(.*)/ index.php
RewriteRule ^(.*)/(.*)/ index.php
index.php
PHP:
<?php
include("_autoload.php");
spl_autoload_register(array(new _autoload(), "autoload"));
error_reporting(E_ALL);
ini_set("display_errors",1);
$urlparts = explode('/',parse_url($_SERVER["REQUEST_URI"],PHP_URL_PATH));
if(isset($urlparts[1]) && isset($urlparts[1]) && class_exists($urlparts[1]."Controller") && method_exists($urlparts[1]."Controller", $urlparts[2])){
$class = $urlparts[1].'Controller';
if(isset($urlparts[3]) && $urlparts[3] != ""){
$controller = new $class();
echo $controller->$urlparts[2]($urlparts[3]);
exit();
}else{
$controller = new $class();
echo $controller->$urlparts[2]();
exit();
}
}else{
$controller = new AlgemeenController();
echo $controller->show();
exit();
}
?>
_autoload.php
PHP:
<?php
session_start();
class _autoload{
public function autoload($class){
ini_set('display_errors',1);
include_once("Library/Smarty/Smarty.class.php");
if (file_exists("Managers/".$class."/".$class.".php")) {
include_once("Managers/".$class."/".$class.".php");
}
if (file_exists("Models/".$class.".php")) {
include_once("Models/".$class.".php");
}
if (file_exists("Controllers/".$class."/".$class.".php")) {
include_once("Controllers/".$class."/".$class.".php");
}
}
}
?>
voorbeeld van een classe
PHP:
<?php
class AdminController{
function __construct(){
$templateManager = new TemplateManager();
$this->smarty = $templateManager->getSmarty();
$this->smarty->assign('menu', $this->smarty->fetch('admin/menu.html'));
$this->smarty->assign('footer', $this->smarty->fetch('footer.html'));
$this->smarty->assign('gebruikersnaam', $_SESSION['gebruiker']);
}
function geenRechten(){
$this->smarty->assign('locatie', 'RECHTEN');
$this->smarty->assign('gebruikersnaam', 'GEEN');
$this->smarty->assign('menu', $this->smarty->fetch('menu.html'));
$this->smarty->assign('melding', $this->smarty->fetch('dialog/geenRechten.html'));
$this->smarty->assign('content', $this->smarty->fetch('Login.html'));
$this->smarty->assign('javascript','<script type="text/javascript" src="http://www.steenredeker.nl/Templates/javascript/login.js" ></script>');
return $this->smarty->fetch('main.html');
}
function home(){
if(isset($_SESSION['gebruikersType']) && ($_SESSION['gebruikersType'] == 'admin')){
$this->smarty->assign('content', $this->smarty->fetch('admin/content.html'));
$this->smarty->assign('locatie', 'Home');
return $this->smarty->fetch('main.html');
}else{
echo $this->geenRechten();
}
}
function gebruikers(){
if(isset($_SESSION['gebruikersType']) && ($_SESSION['gebruikersType'] == 'admin')){
$controller = new DatabaseManager();
$this->smarty->assign('gebruikers', $controller->gebruikers());
$this->smarty->assign('gebruikersnaam', $_SESSION['gebruiker']." (".$_SESSION['gebruikersType'].")");
$this->smarty->assign('locatie', 'Gebruikers');
$this->smarty->assign('content', $this->smarty->fetch('admin/gebruikers/content.html'));
$this->smarty->assign('locatie', 'Gebruikers');
return $this->smarty->fetch('main.html');
}else{
echo $this->geenRechten();
}
}
}
?>
Begrijp je het niet, dan heb ik het vast verkeerd uitgelegd en leg ik het nog een keer uit als dit nodig is.