简体   繁体   English

使用Slim PHP框架实现干净的URL

[英]Using Slim PHP framework to achieve clean url

I am trying to clean my url, and since I am already using the slim framework for php, I thought i might use that has a tool to achieve clean url rather than .htaccess. 我正在尝试清理我的URL,并且由于我已经在使用PHP的苗条框架,所以我认为我可能会使用该工具来实现清理URL而不是.htaccess。

For example, I have the following code: 例如,我有以下代码:

$app->get('/onemonth', function() use($app){
  $app->render('searchPage.php?in_one_month');
})->name('onemonth');

It will only work if i remove the uri of searchPage.php. 它只有在我删除searchPage.php的uri时才有效。 In other words, if i just have it as such: 换句话说,如果我只是这样的话:

  $app->render('searchPage.php');

Any suggestions would be greatly appreciated. 任何建议将不胜感激。

I'm not sure if I understood correctly what you are trying to do. 我不确定我是否正确理解您要做什么。 I guess you want to pass some argument to your searchPage.php file? 您想将一些参数传递给您的searchPage.php文件?

If that's the case you can do the following: 在这种情况下,您可以执行以下操作:

$app->render('searchPage.php', array('in_one_month' => true));

Then, in your searchPage.php file you should have access to $data['in_one_month'] (I haven't tested the last bit) 然后,在您的searchPage.php文件中,您应该可以访问$data['in_one_month'] (我还没有测试最后一点)

Edit: 编辑:

I set up a small repository for demonstration: GitHub 我建立了一个小型存储库进行演示: GitHub

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

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