index.php页面无法在共享托管中使用苗条的框架API

时间:2019-02-04 20:56:52

标签: php slim

我在Godaddy创建了一个苗条的项目。创建后,我通过访问pctechtips.org/apps/slimpro/public验证一切正常,并获得了苗条的网页。公共目录中的默认index.php包含一些代码来显示该页面。当我删除代码并将其替换为我的代码时。它不显示任何内容。怎么了? 默认苗条安装index.php

<?php
if (PHP_SAPI == 'cli-server') {
    // To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
    $url  = parse_url($_SERVER['REQUEST_URI']);
    $file = __DIR__ . $url['path'];
    if (is_file($file)) {
        return false;
    }
}

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

session_start();

// Instantiate the app
$settings = require __DIR__ . '/../src/settings.php';
$app = new \Slim\App($settings);

// Set up dependencies
require __DIR__ . '/../src/dependencies.php';

// Register middleware
require __DIR__ . '/../src/middleware.php';

// Register routes
require __DIR__ . '/../src/routes.php';

// Run app
$app->run();

我的index.php页面

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';

$app = new \Slim\App;
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");

    return $response;
});
$app->run();
?>

1 个答案:

答案 0 :(得分:0)

我认为这里的问题是关于作曲家自动加载文件的路径 在公共目录中不正确

默认使用index.php

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

在您的代码中

require 'vendor/autoload.php';