Example #1
0
<?php

namespace App;

use App\Router\Engine as RouterEngine;
use App\Router\Router;
use App\Router\Route;
Router::setEngine(new RouterEngine());
Router::post("/hello/:name/attitude/:att", function ($name, $attitude) {
    echo "Hello " . $name . ". Your attitude is " . $attitude;
});
Router::static("/pic", "/home/marcel/Bilder/Marcel_Mundl.JPG", "image/jpeg", false);
Router::all("/test", "App\\Test::testPage");
Router::get("/hello/:greeter/aaa/:bbb", function ($a, $b) {
    echo "hello " . $a . " " . $b;
});
Router::all("/.*", function () {
    header("HTTP/1.1 403 FORBIDDEN");
});
Example #2
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();
Example #3
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";
}