<?php
include_once 'config.php';
include_once 'router.php';
session_start();
function loader( $class ) {
$directories = [
'model/',
'controller/'
];
foreach( $directories as $directory ) {
if( file_exists( $directory.$class.'.php') ) {
include_once $directory.$class.'.php';
}
}
}
spl_autoload_register('loader');
if( !isset($_GET['action']) )
{
$action = $_GET['action'];
}
else
{
$action = 'default';
}
$db = new DB($config);
router($action,$db);
^
INDEX
===
<?php
function router($action)
{
switch($action) {
case 'default':
$controller = new DefaultController($db);
$controller->index();
break;
case 'show':
$controller = new DefaultController($db);
$controller->show();
break;
case 'indexlist':
$controller = new DefaultController($db);
$controller->indexlist();
break;
default:
$controller = new DefaultController($db);
$controller->index();
}
}
========
<?php
class DefaultController
{
public function index()
{
$content = 'domyslna akcja';
include 'view/main.html.php';
}
public function show()
{
$content = 'inna akcja';
include 'view/main.html.php';
}
public function indexlist()
{
$content = 'akcja indexlist';
include 'view/main.html.php';
}
}
=====
<?php
class DB
{
protected $connection;
public function __construct($config)
{
try {
$dsn ='mysql:host='.$config['host'].';dbname='.$config['dbname'];
$this->connection = new PDO ($dsn, $config['user'],$config['password']);
}
catch (PDOException $e){
echo $e->getMessage();
}
}
public function getConnection()
{
return $this->connection;
}
}
==========
<?php
$config = [
'host' => 'localhost',
'dbname' => 'database',
'login' => 'root',
'password' => 'uczen4',
];
?>
=========
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}