2017-05-05 122 views
1

目前我正在使用ubuntu,我想在我的系統中安裝PHP Slim framework超薄框架無法正常工作

我已經通過命令行安裝了composer,並且還手動安裝了Slim框架,然後我在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框架。

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

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

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

如何安裝或使用超薄框架上運行的API?

+0

您是否檢查安裝指南? https://www.slimframework.com/docs/start/installation.html –

回答

0

這是我使用作曲家安裝的Slim代碼。

的index.php

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', '1'); 

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) { 
    $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/

希望,它會給你一些提示,以解決您的問題。

+0

給了我下面的錯誤。致命錯誤:require():無法打開所需的'vendor/autoload.php'(include_path ='。:/ usr/share/php') – samir

+0

不要有任何'''vendor'''文件夾? – mi6crazyheart

+0

no var/www/html/slim,我手動安裝slim – samir

0

修身找不到供應商文件夾包含在您的composer.json所需的所有修身文件和其他依賴

您必須先安裝

運行此讚揚所有依賴從你的項目目錄

composer install 

然後再次檢查您的路線。如果您沒有Composer,請首先訪問getcomposer.org。

相關問題