doujia1871 2015-01-18 17:55
浏览 180
已采纳

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

I'm using Slim framework for my project. I've copied the Slim folder to my project directory.

No following is the code I'm having issue with :

HTML code (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

    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

As I submit the HTML form by entering some number say 9565665 the 404 Page not found message appears on the browser window.

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.

  • 写回答

1条回答 默认 最新

  • douweibeng5219 2015-01-19 08:35
    关注

    According to the Slim documentation, you are missing the leading /:

    $application->map('/products(/:id)') ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭