Php 如何解决Slim框架错误“;404找不到页面";?

Php 如何解决Slim框架错误“;404找不到页面";?,php,post,dictionary,get,slim,Php,Post,Dictionary,Get,Slim,我正在为我的项目使用Slim框架。我已将Slim文件夹复制到我的项目目录中 以下是我遇到问题的代码: HTML代码(multiplemethods.HTML): <html> <head> <title>Multiple Methods Routing Demo</title> </head> <body> <form action="multiplemethodsroute.php/pro

我正在为我的项目使用Slim框架。我已将Slim文件夹复制到我的项目目录中

以下是我遇到问题的代码:

HTML代码(multiplemethods.HTML):

<html>
  <head>
    <title>Multiple Methods Routing Demo</title>
  </head>
  <body>
    <form action="multiplemethodsroute.php/products" method="GET">

            product id <input type="text" name="id" />
            <br/>
            <input type="submit" />
    </form> 
  </body>   
</html>
<?php

    require 'Slim/Slim.php';

    /* Invoke the static "registerAutoloader()" function defined within Slim class. 
     * Register the autoloader is very important. 
     * Without doing it nothing will work.
    */ 
    \Slim\Slim::registerAutoloader();

    //Instantiate Slim class in order to get a reference for the object.
    $application = new \Slim\Slim();

    $application->map(
        'products(/:id)', 
        function()
        { 
            global $application;
            $id = $application->request->get('id');
            if($id == null)
            {
                $id = $application->request->post('id');
            }
            echo "showing info about product #".$id;
        })->via('GET','POST');      

    $application->run();
?>

多方法路由演示
产品id

PHP代码(multipleMethodRoute.PHP):

<html>
  <head>
    <title>Multiple Methods Routing Demo</title>
  </head>
  <body>
    <form action="multiplemethodsroute.php/products" method="GET">

            product id <input type="text" name="id" />
            <br/>
            <input type="submit" />
    </form> 
  </body>   
</html>
<?php

    require 'Slim/Slim.php';

    /* Invoke the static "registerAutoloader()" function defined within Slim class. 
     * Register the autoloader is very important. 
     * Without doing it nothing will work.
    */ 
    \Slim\Slim::registerAutoloader();

    //Instantiate Slim class in order to get a reference for the object.
    $application = new \Slim\Slim();

    $application->map(
        'products(/:id)', 
        function()
        { 
            global $application;
            $id = $application->request->get('id');
            if($id == null)
            {
                $id = $application->request->post('id');
            }
            echo "showing info about product #".$id;
        })->via('GET','POST');      

    $application->run();
?>

两个文件都是。multiplemethods.html和multiplemethodsroute.php位于同一个名为“slimsamples”的目录中,位置为
/var/www/slimsamples

当我通过输入一些数字(比如9565665)提交HTML表单时,404页面未找到消息出现在浏览器窗口上

控件未进入为map编写的函数中。我在调试过程中对此进行了测试

有人能找出我在这里犯的错误吗


提前感谢。

根据Slim文档,您缺少了领先的/:

$application->map('/products(/:id)') ...

产品(/:id)
前面缺少
/
?@Jasper:非常感谢您指出了确切的问题。在添加了产品(/:id)之后,它对我来说真的非常有效。@Jasper:添加它作为答案。;)