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)') ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码