我正在寻找有关合理的 Cake 方法的建议,以创建基于会话 id 的 url,我可以与其他人共享该 URL,以查看与我所看到的相同的搜索结果。
我知道在标准 php 中,我只需获取会话 id 并将其传递给 url。但我猜测 Cake 可能有一种方法或方法来解决这个问题(我的猜测)。我还无法找到任何具体内容。
关于蛋糕方法的最佳方法有什么想法吗?或者我需要重新发明轮子吗?
您问这个问题是因为您使用的是 POST,因此 URL 不包含搜索参数,而通过 GET 会如此?
我使用以下设计范例来搜索我构建的所有应用程序。
- 搜索表单以 POST 形式提交。
- 在控制器操作中,如果表单作为帖子提交,我会提取搜索参数,然后重定向到包含 (named*) 参数的 URL。
所以操作代码可能看起来像这样:
function search() {
if($this->RequestHandler->isPost()) {
// let's say we extract parameters called $a and $b here
$this->redirect(array(
'action' => 'search',
'a' => $a,
'b' => $b
)
exit();
)
// perform the normal search operation
// the 'a' and 'b' parameters can be accessed in the $this->params['named']
// array, automatically extracted by the CakePHP router using the configuration below.
}
关于命名参数,我将在我的routes.php中进行设置:
Router::connectNamed(array('a', 'b'));
这会导致上面的重定向创建一个漂亮、干净的 URL,例如:
http://example.com/controller/search/a:FOO/b:BAR
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)