Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slim hhvm fortunes, some cleanup, and a little enhancement #2309

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleaning up service definitions.
  • Loading branch information
herloct committed Oct 19, 2016
commit 14a4a825cc13c94b7d36b83731424ad2b06bfda9
24 changes: 13 additions & 11 deletions frameworks/PHP/slim/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

require_once __DIR__.'/vendor/autoload.php';

$app = new \Slim\App;
$container = $app->getContainer();
$container['db'] = function ($c) {
$db = $c['settings']['db'];
$pdo = new PDO('mysql:host=localhost;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
$container['view'] = new \Slim\Views\PhpRenderer("templates/");
$app = new Slim\App(array(
'db' => function ($c) {
$pdo = new PDO('mysql:host=localhost;dbname=hello_world;charset=utf8', 'benchmarkdbuser', 'benchmarkdbpass');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);

return $pdo;
},

'view' => function ($c) {
return new Slim\Views\PhpRenderer("templates/");
}
));

// Test 1: Plaintext
$app->get('/plaintext', function ($request, $response) {
Expand All @@ -30,7 +33,6 @@
;
});


// Test 3: Single database query
$app->get('/db', function ($request, $response) {
$sth = $this->db->prepare('SELECT * FROM World WHERE id = ?');
Expand Down