Created
April 10, 2013 22:07
-
-
Save mochja/5358891 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 | |
// phpinfo(); exit; | |
require __DIR__.'/../vendor/autoload.php'; | |
Tracy\Debugger::enable(false); | |
class TwigView extends \Slim\View { | |
private $twig; | |
public function __construct() { | |
parent::__construct(); | |
$loader = new Twig_Loader_Filesystem(__DIR__.'/../templates'); | |
$this->twig = new Twig_Environment($loader, array( | |
'cache' => __DIR__.'/../temp', | |
'auto_reload' => true | |
)); | |
} | |
public function render($template) { | |
return $this->twig->render($template, $this->data); | |
} | |
} | |
$app = new Slim\Slim(array( | |
'view' => new TwigView | |
)); | |
// $db = new PDO('mysql:host=127.0.0.1;dbname=test;charset=utf8', 'root', 'root', array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false)); | |
$db = mysqli_connect('127.0.0.1', 'root', 'root'); | |
mysqli_query($db, 'USE test'); | |
$app->get('/hello/:name', function ($name) use ($app, $db) { | |
// $stmt = $db->query("SELECT id, title, text FROM posts"); | |
// $posts = $stmt->fetchAll(PDO::FETCH_ASSOC); | |
$posts = mysqli_query($db, 'select id, title, text from posts'); | |
$app->render('default.tpl', array( 'name' => $name, 'posts' => $posts )); | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment