简体   繁体   English

如何解决Slim框架错误“找不到404页”?

[英]How to resolve the Slim framework error “404 Page Not Found”?

I'm using Slim framework for my project. 我正在为我的项目使用Slim框架 I've copied the Slim folder to my project directory. 我已将Slim文件夹复制到我的项目目录中。

No following is the code I'm having issue with : 以下是我遇到的问题的代码:

HTML code (multiplemethods.html): 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 Code(multiplemethodsroute.php): PHP代码(multiplemethodsroute.php):

<?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();
?>

Both the files viz. 这两个文件即。 multiplemethods.html and multiplemethodsroute.php are present in the same directory titled "slimsamples" at location /var/www/slimsamples /methodsroute.php和/multiplemethodsroute.php存在于/var/www/slimsamples位置的同一目录中,名称为“ slimsamples”

As I submit the HTML form by entering some number say 9565665 the 404 Page not found message appears on the browser window. 当我通过输入一些数字(例如9565665)提交HTML表单时,浏览器窗口上会显示404页面未找到消息。

The control is not going inside the function written for map. 控件没有进入为地图编写的函数内。 I tested this during debug process. 我在调试过程中对此进行了测试。

Can someone please find out the mistake I'm making here? 有人可以找出我在这里犯的错误吗?

Thanks in advance. 提前致谢。

根据Slim文档,您缺少前导/:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM