コード例 #1
0
<?php

require_once 'vendor/autoload.php';
use Slim\Slim;
use Slim\Extras\Middleware\CsrfGuard;
$directory = get_template_directory() . "/app";
$assets = get_template_directory_uri();
$loader = new Twig_Loader_Filesystem($directory);
$twig = new Twig_Environment($loader);
$twig->addExtension(new Twig_Extensions_Extension_I18n());
// here I can use MongoDB if i want to. very flexible.
$mongo = new MongoClient("mongodb://localhost/?journal=true&w=1&wTimeoutMS=20000");
$mongodb = $mongo->react_blog;
$MongoUser = $mongodb->users;
$app = new \Slim\Slim();
$app->add(new \Slim\Middleware\SessionCookie(array('expires' => '20 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slimblog_dev_session', 'secret' => 'YOU_ARE_SUCH_A_COOL_KID', 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC, 'date.timezone' => 'UTC')));
$app->add(new CsrfGuard());
$app->get('/', function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } else {
        echo "You gonna login first";
    }
});
$app->get('/app', function () use($app, $twig, $assets) {
    $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets);
    if (isset($_SESSION['app_id'])) {
        echo $twig->render('views/index.php', $data);
    } else {
        echo "You gonna login first bro";