简单php Slim项目错误

简单php Slim项目错误,php,apache,wamp,wampserver,slim,Php,Apache,Wamp,Wampserver,Slim,我已经在安装了WAMP服务器的Windows 8.1上使用PHPStorm 8创建了一个简单的Slim微框架项目。默认情况下会设置所有WAMP服务器设置 我创建了一个名为pr1 我使用了“Init Composer…”,然后添加了一些依赖项,如slim/slim,slim/views,twig/twig 然后,我尝试创建一个简单的应用程序,就像主页上的一个给定示例: 我在我的项目文件夹中创建了名为index.php的文件 index.php 代码: 然后我创建了文件app.php 代码 在此之后

我已经在安装了WAMP服务器的Windows 8.1上使用PHPStorm 8创建了一个简单的Slim微框架项目。默认情况下会设置所有WAMP服务器设置

我创建了一个名为
pr1
我使用了
“Init Composer…”
,然后添加了一些依赖项,如
slim/slim
slim/views
twig/twig

然后,我尝试创建一个简单的应用程序,就像主页上的一个给定示例:

  • 我在我的项目文件夹中创建了名为
    index.php
    的文件 index.php
  • 代码:

  • 然后我创建了文件
    app.php
  • 代码

  • 在此之后,我试图在Chrome中运行我的项目,但出现了404错误
  • 然后我尝试通过url传递我的名字:
    http://localhost:63342/pr1/wade
    出现PHPStorm错误
  • 完成这些步骤后,我尝试在浏览器中关闭PHPStorm和我的项目:
  • 看起来有一个典型的Slim 404错误,但当我再次尝试通过url传递我的名字时,它给了我这个错误:


    例如,您需要包括index.php
    要摆脱index.php,请根据您的Web服务器使用.htaccess或类似的工具,因为Apachi不知道如何处理所有浏览器请求。因此,我创建了一个简单的.htaccess文件:

        RewriteEngine On
    
    # Some hosts may require you to use the `RewriteBase` directive.
    # If you need to use the `RewriteBase` directive, it should be the
    # absolute physical path to the directory that contains this htaccess file.
    #
    # RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]
    
    在此之后,我需要在WAMP设置中使用rewrite_模块

    当我在浏览器中通过资源管理器打开project时,它可以完美地与project配合使用

    在此之后,我将服务器设置为:


    这使我能够通过PHPStorm预览所有更改

    我在项目的根目录中创建了一个.htaccess文件,现在它可以工作了。
    require 'vendor/autoload.php';
    
    $app = new \Slim\Slim();
    
    $app->get('/:name', function ($name) {
       echo "Hello, $name";
    });
    
    $app->run();
    
        RewriteEngine On
    
    # Some hosts may require you to use the `RewriteBase` directive.
    # If you need to use the `RewriteBase` directive, it should be the
    # absolute physical path to the directory that contains this htaccess file.
    #
    # RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [QSA,L]