-
-
Save michalhisim/5224161 to your computer and use it in GitHub Desktop.
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 | |
require_once(Application::MODELS . 'Menu.php'); | |
/** | |
* Návrhový vzor Singleton => může existovat pouze jedna jediná instance. | |
*/ | |
class Application{ | |
private static $instance = false; | |
const APP = WEB_ROOT . 'app/'; | |
const MODELS = APP . 'models/'; | |
const TEMPLATES = APP . 'templates/'; | |
const CONTROLLERS = APP . 'controllers/'; | |
private $controllers; | |
private $runningController = NULL; | |
private function __construct(){ | |
} | |
public static function getInstance(){ | |
if(self::$instance === false){ | |
self::$instance = new Application; | |
} | |
return self::$instance; | |
} | |
/** | |
* Na základě URL určí, která Controller se má spustit. | |
* vytvoří instanci controlleru | |
*/ | |
private function router(){ | |
//todo routing dle URL | |
//pro stestování natvrdo vracíme instanci UvdController | |
if($this->runnongController == NULL) | |
{ | |
$db = new Mysql(); //předají se přítupové údaje k DB | |
$menuModel = new Menu($db); // předáme modelu instanci databáze | |
$this->runningController = new HomepageController($menuModel); // předáme kontroleru instanci modelu | |
} | |
$this->runningController->action(); // spustí akci controlleru, popřípadě ji přeá nějaké parametry z URL | |
} | |
public function render(){ | |
//todo etc | |
$this->runningController->render(); // vkresíle view | |
} | |
} | |
?> |
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 | |
abstract class BaseController{ | |
protected $model; | |
public function __construct($model){ | |
$this->model = $model; | |
} | |
public function action(){ | |
} | |
public function render(){ | |
//todo získat položky menu z DB a "předat" je do view | |
} | |
} | |
?> |
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> | |
<html lang="cs-cz"> | |
<head> | |
<title></title> | |
<meta charset="UTF-8" /> | |
<meta name="description" content="" /> | |
<meta name="keywords" content="" /> | |
<link rel='stylesheet' href='./view/css/css.css' type='text/css' /> | |
</head> | |
<body> | |
<?php | |
/** | |
* Include Hlavní šablony | |
*/ | |
require_once 'horniMenu.php'; | |
?> | |
</body> | |
</html> |
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 require_once(Application::TEMPLATES . 'header.php') ?> | |
<div id='kontejner'> | |
<div id='pruh'> | |
</div> | |
<a href='/index.php'> | |
<div id='logo'> | |
</div> | |
</a> | |
<div id='pruh'> | |
</div> | |
<div id='navhore'> | |
<?php | |
?> | |
</div> | |
<div id='rubrika'> | |
<h1>RUBRIKA</h1> | |
</div> | |
<div id='blok'> | |
<?php | |
?> | |
</div> | |
<div id='bok'> | |
<div id='bokneco'> | |
<h1>Pod-kategorie</h1> | |
</div> | |
<div id='boknecodole'> | |
<br /> | |
<?php | |
?> | |
</div> | |
<div id='bokneco'> | |
<h1>Přihlášení</h1> | |
</div> | |
<div id='boknecodole'> | |
<?php | |
?> | |
</div> | |
</div> | |
</div> | |
<div id='pata'> | |
<hr /> | |
<p><small> © Valenta David | 2013-2103 | Projekt: web školních novin</small></p> | |
</div> |
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 | |
/** | |
* Třída Kontroleru!!! | |
* @version 1.0.0 | |
*/ | |
class HomepageController extends BaseController { | |
public function __construct(Menu $menuModel){ | |
parent::__construct($menuModel); | |
} | |
public function render(){ | |
parent::render(); | |
require(Application::TEMPLATES . 'homepage.php'); | |
} | |
} | |
?> |
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 | |
/** | |
* @author Valenta David <[email protected]> | |
* @version 1.0.0 | |
* Web školních novin | |
*/ | |
const WEB_ROOT = '/'; | |
require_once(WEB_ROOT . 'Application.php'); | |
$app = Application::getInstance(); | |
$app->render(); | |
?> |
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 | |
/** | |
* třída pro připojení k Mysql | |
* @version 1.0.0 | |
*/ | |
class Mysql { | |
private $connection; | |
/** | |
* Připojení k DB | |
*/ | |
public function __construct(/*získá přístupové údaje*/) { | |
$this->connection = mysql_connect(/*předá přístupové údaje*/) or die(mysql_error()); | |
//todo ošetřit vyjímky, vybrat DB | |
//mysql_select_db(/**/) or die(mysql_error()); | |
} | |
/** | |
* query | |
*/ | |
public function query($sql) { | |
$result = mysql_query($sql, $this->connection); | |
// todo vracet nebufferovaná data | |
//return fetch_.... | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment