예제 #1
0
<?php

/**
 * MVC-Simple simple application PHP
 *
 * @package mvc-simple
 * @author Wellington dos Santos <*****@*****.**>
 * @license http://opensource.org/licenses/MIT MIT License
 */
define('ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('APP', ROOT . 'core' . DIRECTORY_SEPARATOR);
if (file_exists(ROOT . 'vendor/autoload.php')) {
    require ROOT . 'vendor/autoload.php';
}
if (file_exists(APP . 'config/config.php')) {
    require APP . 'config/config.php';
}
use App\Router\Router;
if (array_key_exists('url', $_GET)) {
    $route = new Router($_GET['url']);
} else {
    $route = new Router(URL_DEFAULT);
}
$route->get('/', "Posts.home");
$route->get('/username/:name', function ($name) {
    echo "Hello " . $name;
})->with('name', '[a-z]+');
$route->post('/user', "Posts.setName");
$route->run();
예제 #2
0
require 'vendor/autoload.php';
use ORM\Entity\Manager;
use Config\ORM;
use App\Router\Router;
$ORM = new ORM();
try {
    $router = new Router($_GET['url']);
    $router->get('/', function () {
        echo "Homepage";
    });
    $router->get('/posts', function () {
        echo 'Tous les articles';
    });
    $router->get('/article/:slug-:id/:page', "Posts#show")->with('id', '[0-9]+')->with('page', '[0-9]+')->with('slug', '([a-z\\-0-9]+)');
    $router->get('/article/:slug-:id', "Posts#show")->with('id', '[0-9]+')->with('slug', '([a-z\\-0-9]+)');
    $router->post('/posts/:id', function ($id) {
        echo 'Poster pour l\'article ' . $id . '<pre>' . print_r($_POST, true) . '</pre>';
    });
    $router->get('/home', "Home#");
    $router->get('/base', "Base#");
    //    $Post = new Post\Post(); //New post
    //    $Post->setTitle('My post title'); //Insert title
    //    $Post->setContent('My post content'); //Insert content
    //    $ORM->EM->persist($Post); //Insert post in database
    $router->run();
} catch (Exception $e) {
    $a = new \Config\ErrorLog();
    $a->errorLog($e->getMessage());
    echo 'Exception reçue : ', $e->getMessage(), "\n";
}