.htaccess
Kód: Vybrať všetko
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mvc/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule> Kód: Vybrať všetko
<?php
//Define our site URL
define("BASE_PATH", " http://nieco.sk");
//Define our basepath
$path = "/mvc";
//Take the initial PATH.
$url = $_SERVER['REQUEST_URI'];
$url = str_replace($path,"",$url);
//creates an array from the rest of the URL
$array_tmp_uri = preg_split('[\\/]', $url, -1, PREG_SPLIT_NO_EMPTY);
//Here, we will define what is what in the URL
$array_uri['controller'] = $array_tmp_uri[0]; //trieda
$array_uri['method'] = $array_tmp_uri[1]; //funkcia
$array_uri['var'] = $array_tmp_uri[2]; //var
if(!isset($array_uri['controller'])) $array_uri['controller']="index";
//Load our base API
require_once("base.php");
//loads our controller
$application = new Application($array_uri);
$application->loadController($array_uri['controller']);
?> Kód: Vybrať všetko
<?php if (!defined('BASE_PATH')) exit('Not allowed.');
class Application
{
private $uri;
private $model;
function __construct($uri)
{
$this->uri = $uri;
}
function loadLibrary($library){
$lib = "application/libraries/".$library.".php";
if(!file_exists($lib)) die("Zadana knihovna neexistuje");
require_once($lib);
$libini = new $library();
return $libini;
}
function loadController($class)
{
$file = "application/controller/".$this->uri['controller'].".php";
if(!file_exists($file)) die("Zadana stranka neexistuje");
require_once($file);
$controller = new $class();
if(method_exists($controller, $this->uri['method']))
{
$controller->{$this->uri['method']}($this->uri['var']);
} else {
$controller->index();
}
}
function loadView($view,$vars="")
{
if(is_array($vars) && count($vars) > 0)
extract($vars, EXTR_PREFIX_SAME, "wddx");
require_once('application/view/'.$view.'.php');
}
function loadModel($model)
{
require_once('application/model/'.$model.'.php');
$this->$model = new $model;
}
}
?>