苗条的框架-无法解释带点的路线 [英] Slim framework - cannot interpret routes with dot

查看:69
本文介绍了苗条的框架-无法解释带点的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题声明



我目前正在使用内部RESTful API,并且使用我们的主要域名作为环境标识符。但是,我注意到Slim根本不喜欢在其中添加点的路线。



示例案例



我有一个使用PHP的内置Web服务器运行的本地Web服务器,我调用了 php -S 0.0.0.0:5000 使其运行。



一旦网络服务器启动,索引页面上就会出现一个简单的 hello world。



然后我设置了以下路线:

  $ app-> get('/:domain /:id',function($ domain,$ id)
{
echo $ domain。''。$ id;
}

通过此操作,我设置了希望解析 0.0.0.0:5000/apple.com/juicers 。我尝试了 0.0.0.0:5000/apple/juicers 和该页面会打印出苹果榨汁机,但是出现 0.0.0.0:5000/apple.com/juicers 时,出现 404 Not Found 错误。 / p>

到目前为止我已经尝试过的



URL重写



我也在Slim框架的Github问题中查找了Google上的可用资源,似乎有人遇到了类似的问题: https://github.com/codeguy/Slim/issues/359



该故障单中建议的解决方案是: URL重写修复。做到这一点,但无济于事。我在项目目录的根目录下设置了 .htaccess ,并在Mac的httpd中打开了 AllowOverRide All 。 conf文件。



php -S 0.0.0.0:5000 index.php



代替运行 php -S 0.0.0.0:5000 本身,我在index.php上运行了该命令。在这一点上,苗条的框架没有抛出未找到错误,而是解决了我的基本路线,该路线如下所示:

  $ app-> get('/',function(){echo hello world;}); 



谢谢



我在机智的到来,我们将不胜感激。非常感谢您的阅读!

解决方案

根本问题-PHP开发服务器



在使用了不同的Slim条件和实验之后,我开始更仔细地研究服务器级别,并确保将URL正确传递给Slim路由。



原来这是PHP开发服务器的问题,可通过 php -S 命令获得该问题。



一个快速的Google搜索显示,其他几个人遇到了相同的问题,这是服务器问题,而不是Slim中的错误。



解决方案



要测试我的解决方案,我运行了MAMP,并将所有文件转移了过来。然后,我编写了.htaccess文件,将所有请求重定向到index.php。



关键时刻:



我键入 localhost:8888 / campaigns / demo.com/12 ,当我看到写着一行美丽,华丽的 demo.com/12 时,一道喜悦波涛涌动浏览器! (对于该特定路线,我有一个 echo 语句)经过一周多的故障排除和修补终于有了成果!



庆祝性的贺拉!



\(^ O ^)/ Apache的贺拉!



感谢您的光临帮助@adosaiguas!


Problem Statement

I'm currently working on an internal RESTful API, and I'm using our main domain name as an environment identifier. However, I noticed that Slim does not like it at all for a route to have dot in there.

Sample case

I have a local web server running using PHP's built-in webserver, and I invoked php -S 0.0.0.0:5000 to get it running.

Once the web server is up, I have a simple 'hello world' on the index page. Everything's working fine and dandy.

I then set up a route as following:

$app->get('/:domain/:id', function($domain, $id) 
{
    echo $domain . ' ' . $id;
} 

With this, I set up the route to hopefully resolve 0.0.0.0:5000/apple.com/juicers. I tried with 0.0.0.0:5000/apple/juicers and the page prints out apple juicers. But with 0.0.0.0:5000/apple.com/juicers, I get a 404 Not Found error.

What I've tried so far

URL Rewrite

I looked up the available resources on Google, and from Slim framework's Github issues as well. It seems like someone encountered a similar issue: https://github.com/codeguy/Slim/issues/359

The proposed solution in that ticket was: URL rewriting fix. I tried that but to no avail. I set up a .htaccess at the root of my project directory, and turned on AllowOverRide All in my Mac's httpd.conf file.

php -S 0.0.0.0:5000 index.php

Instead of running php -S 0.0.0.0:5000 by itself, I ran the command on index.php. At this point, instead of throwing a Not Found error, the slim framework is resolving to my base route, which I set up as follows:

$app->get('/', function() { echo "hello world"; });

Thank you

I'm at my wit's end, and any help will be highly appreciated. Thank you so much for reading!

解决方案

Root issue - PHP Development server

After playing with different Slim conditions and experiments, I started to look closer at the server level and making sure that the URL was passed correctly to the Slim routes.

Turns out this was an issue with PHP's development server, which is available through the php -S command.

A quick google search revealed that several others had encountered the same issue, and it was a server issue, rather than a bug in Slim.

Solution

To test out my solution, I ran MAMP, and transferred all my files over. And then I wrote the .htaccess to redirect all requests through to index.php.

The moment of truth:

I typed in localhost:8888/campaigns/demo.com/12 and a wave of joy surged through my veins as I saw a line of beautiful, gorgeous demo.com/12 written across the browser! (I have an echo statement for that particular route) A week-plus of troubleshooting and tinkering around has finally bore fruit!

Celebratory Hoorah!

\(^O^)/ Hoorah for Apache!

Thanks for your help @adosaiguas!

这篇关于苗条的框架-无法解释带点的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆