2016-07-13 4 views
0

Slimについて以下のようにしてTutorial(9:48)を実行した後、スリム機能をテストすると、まだ「ページが見つかりません」というメッセージが表示されます。 programmがeg.Ifは「http://localhost/authentication/public/test/Hello」で検索特定のポイントの後、ページが「こんにちは」エコーすべきである検索バーに入力した任意の単語をエコーすることになっている

、ページが「こんにちは」をエコーする必要があります。

これは、.htaccessファイルを使用してindex.phpへのリンクを再ルーティングすることによって行われます。 index.phpファイルは、start.phpというphpファイルを実行します。

なぜこれが機能しないのでしょうか?

スリムv3.xの

の.htaccess

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [QSA,L] 

のindex.php

<?php 

require '../app/start.php'; 

$app->run(); 
?> 

start.php

<?php 

use Slim\App; 

session_cache_limiter(false); 
session_start(); 

ini_set('display_errors', 'On'); 

define('INC_ROOT', dirname(__DIR__)); 

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

$app = new App(); 

$app->get('/test/:name', function($name) { 
echo "Hello! {$name}"; 
}); 
?> 
+0

Apache Webサーバーを使用していますか? .htaccessとindex.phpはディレクトリ構造のどこにありますか?どのURLにindex.phpに直接アクセスしていますか?http://localhost/authentication/public/index.phpですか? – jirka

答えて

1

問題I Slim 3を使用してSlim 2 Codeを使用しようとしています。 コードを新しい構造に変更するか、v2に戻す必要があります。

slimframework homepage上のあなたのような例があります:

//example taken from slimframework.com 
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(); 

私はofficial docs一読をお勧めしたいです。

+0

さて、私は約4ヶ月間Slim 3を使用してきましたが、それは絶対的な喜びです。それはあなたに出発点を与え、あなたは複雑なものとしてアプリケーションを作ることができますまたはシンプルなまま、現代のWeb開発の最も基本的なパターンにのみ結び付けて – charmeleon