Last active
August 29, 2015 14:03
-
-
Save Kubo2/08c9118d2b2a95a26bc9 to your computer and use it in GitHub Desktop.
Funkčné riešenie routovania pekných URL adries v podadresári na testovacom serveri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// autoloading | |
spl_autoload_register(function($nazov) { | |
if(is_file(__DIR__ . "/kontrolery/$nazov.php")) { | |
require(__DIR__ . "/kontrolery/$nazov.php"); | |
} else if(is_file(__DIR__ . "/modely/$nazov.php")) { | |
require(__DIR__ . "/modely/$nazov.php"); | |
} else { | |
throw new DomainException("Nie je možné načítať triedu $nazov", E_ERROR); | |
} | |
}, false, true); | |
/** | |
* Namiesto skutočnej hodnoty {@code $_SERVER["REQUEST_URI"]} sa použije táto ošetrená. | |
* Táto po ošetrení neobsahuje cestu k (pod)adresáru, v ktorom sa nachádza aplikácia. | |
* Jediná nevýhoda je vznik prirodzených duplicít {@link http://www.jakpsatweb.cz/seo/kanonizace.html} | |
* | |
* @var string | |
*/ | |
$_SERVER["REQUEST_URI"] = substr( | |
preg_replace('~/{2,}~', '/', $_SERVER["REQUEST_URI"]), | |
strlen(dirname($_SERVER["PHP_SELF"])) | |
); | |
// application set-up | |
$smerovac = new SmerovacKontroler; | |
// routeru vložíme ako argument pole so správne ošetreným REQUEST_URI | |
$smerovac->spracuj([ $_SERVER["REQUEST_URI"] ]); | |
// plus šablóna |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<!-- ! aby fungovali relatívne odkazy --> | |
<base href="<?= ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != "off" ? "https" : "http") . '://' . $_SERVER["SERVER_NAME"] . (strlen($rel = dirname($_SERVER["PHP_SELF"])) > 1 ? $rel : '')) ?>/" > | |
<meta charset="UTF-8"> | |
<title><?= $titulek ?></title> | |
<? if(isset($popis)): ?><meta name="description" content="<?= $popis ?>"><? endif ?> | |
<link rel="stylesheet" href="ui.style" type="text/css"> | |
<script>document.createElement('footer');</script> | |
</head><body> | |
<div id="header"> | |
<h1>DevbookMVC - ukázkový web</h1> | |
</div><div id="nav"> | |
<ul> | |
<li><a href="clanek/uvod">Úvod</a></li> | |
<li><a href="clanek">Články</a></li> | |
<li><a href="kontakt">Kontakt</a></li> | |
</ul> | |
</div><br clear="all"> | |
<div id="content-main"> | |
</div> | |
<footer> | |
<p>Ukázkový tutoriál pro jednoduché MVC z programátorské sociální sítě | |
<a href="http://www.devbook.cz" target="_blank">devbook.cz</a>.</p> | |
</footer> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment