简体   繁体   English

cakephp和路由-如何在URL中使用GET参数

[英]cakephp & routes - how to use a GET param in the URL

I have a simple GET form which allows the user to type in a location, then select a couple of other options and perform a search. 我有一个简单的GET表单,该表单允许用户键入一个位置,然后选择几个其他选项并执行搜索。

So at the minute the url for this action is: controller/search?area=london&option1=whatever&option2=whateverelse 因此,此刻此操作的网址为:controller / search?area = london&option1 = whatever&option2 = wevereverelse

I'd like the url to be: controller/search/london?option1=whatever&option2=whateverelse 我希望网址为:controller / search / london?option1 = whatever&option2 = whateverelse

so in other words the GET param for the area would be incorporated into the url but not as a NVP. 因此换句话说,该区域的GET参数将被合并到url中,而不是作为NVP。

Is there a way to do this? 有没有办法做到这一点? I'm a bit confused about routing or if there's another way? 我对路由还是有些困惑?

Thanks 谢谢

Use routing and the CakeDC search plugin . 使用路由CakeDC搜索插件 If you do not have yet read about routing you should do it, its a very powerful feature. 如果您尚未阅读有关路由的信息,则应该这样做,它是一项非常强大的功能。

Route::connect('/search/:city/*', array('controller' => 'search', 'action' => 'index'), array('pass' => array('city'), 'city' => 'a-zA-Z0-9_-]+')));

Just wrote that down without testing, try it if does not work put some effort into it. 只是写下而不进行测试,如果不起作用请尝试一下。 This will make the city become the first arg of SearchController::index($city = null); 这将使城市成为SearchController :: index($ city = null);的第一个参数。

The search plugin will help you with mapping the query params to search conditions that can be used to retrieve the data from the database, see its readme.md how to do it. 搜索插件将帮助您将查询参数映射到可用于从数据库中检索数据的搜索条件,请参阅其readme.md如何进行操作。

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

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