简体   繁体   中英

CodeIgniter Change POST method URL

I basically have a search box on the index of my site and when a user tries to search anything the function q is called from the controller ( search.php ) and the method used by the form is post so basically i end up with this following URL youdomain.com/search/qi wanted to get something like this youdomain.com/search/your-search-query.html i know this is possible using routes i tried search'ing alot but failed in getting something like this.

I dont wanna change my form method as if i change it to get i will need to also change the config.php URI to query which is kind of ugly .

So is there any solution to this ?

A question: What do you want to happen if a user types in the address youdomain.com/search/your-search-query.html directly? If you want the search results also in this case (which is a right thing to do), you will have to implement GET search anyway.

I shouldn't be even telling you this, because it is in my opinion a bad thing to do here, but you can catch the submit event with javascript, change the url of the request and then send it.

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