-1
slim微型框架中index.php的示例文件來自公共文件夾? 我使用使用composer和index.php文件的slim/slim-skeleton,因爲這不起作用?slim中index.php的正確語法文件
slim微型框架中index.php的示例文件來自公共文件夾? 我使用使用composer和index.php文件的slim/slim-skeleton,因爲這不起作用?slim中index.php的正確語法文件
好的。我得到了答案。
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$container = new \Slim\Container;
$container['db'] = getConnection();
$app = new \Slim\App($container);
$app->get('/', function ($request, $response, $args) {
$response->write("Welcome to Slim!");
return $response;
});
function getConnection() {
$dbhost="localhost";
$dbuser="xxx";
$dbpass="xxxxxxxx";
$dbname="xxxxxx";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// var_dump($dbh);
return $dbh;
}
$app->run();
?>