简体   繁体   中英

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.

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. 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?

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)

Edit:

I set up a small repository for demonstration: GitHub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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