细长的框架不起作用



当前我正在使用Ubuntu,我想在系统中安装PHP Slim framework

我通过命令行安装了作曲家,还可以手动安装Slim Framework,然后我在Slim文件夹中创建了一个index.php文件,并在该文件中放置以下代码,当我尝试运行该文件时看不到。

<?php
require 'vendor/autoload.php';
$app = new SlimApp();
//slim application routes
$app->get('/', function ($request, $response, $args) { 
 $response->write("Welcome: This is AlphansoTech Tutorial Guide");
 return $response;
});
$app->run()
?>

我尝试致电http://localhost/slim/index.php,向我展示空白屏幕。

我不知道我第一次安装和使用纤细的框架会发生什么。

我尝试关注URL安装Slim Framework。

http://www.alphansotech.com/blogs/php-restful-api-framework-slim-tulorial/

https://www.slimframework.com/docs/tutorial/first-app.html

https://www.slimframework.com/docs/start/installation.html

如何使用Slim Framework安装或运行API?

Slim找不到供应商文件夹,其中包含您 Composer.json

中所需的所有苗条文件和其他依赖项

您必须先安装所有依赖项

从您的项目目录中运行此赞誉

composer install 

然后再次检查您的路线。如果您没有作曲家,请访问GetComposer.org。

这是我使用Composer安装的Slim代码。

index.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require 'vendor/autoload.php';
$app = new SlimApp;
$app->get('/hello/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");
    return $response;
});
$app->run();

我用于访问该文件的URL是http://localhost/slim/index.php/hello/suresh

安装文件夹名称-slim

输出接收

Hello, suresh

文档遵循 -https://www.slimframework.com/

希望,它会给您一些提示来解决您的问题。

我认为问题在于创建$ app。为我创建应用程序的工作方式是:

use SlimFactoryAppFactory;
$app = AppFactory::create();

最新更新