【问题标题】:Correct syntax file for index.php in slimslim 中 index.php 的正确语法文件
【发布时间】:2017-08-25 05:42:58
【问题描述】:

在公用文件夹中的超薄微型框架中的 index.php 示例文件? 我使用了使用 composer 和 index.php 文件的 slim/slim-skeleton,因为它不起作用?

【问题讨论】:

    标签: php slim


    【解决方案1】:

    好的。我得到了答案。

    <?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();
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 2010-11-19
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多