在 Cakephp 中创建有意义的添加 URL
对于我的网站,我有许多订单
,每个订单都包含许多报价
。报价始终与单个订单相关联,因此在报价控制器中,我添加了一个引用其订单的报价:
function add($orderId) {
// function here
}
调用 URL 看起来有点像
http://www.example.com/quotes/add/1
我想到,如果 URL 看起来更像是更有意义
http://www.example.com/orders/1/quotes/add
由于报价被添加到订单 1 中。
这可以在 CakePHP 中实现吗?
For my site I have a number of Orders
each of which contains a number of Quotes
. A quote is always tied to an individual order, so in the quotes controller I add a quote with reference to it's order:
function add($orderId) {
// function here
}
And the calling URL looks a bit like
http://www.example.com/quotes/add/1
It occurred to me the URLs would make more sense if they looked a bit more like
http://www.example.com/orders/1/quotes/add
As the quote is being added to order 1.
Is this something it's possible to achieve in CakePHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看定义路由的文档。
像这样的事情应该可以解决问题:
您将能够使用
QuotesController::add()
中的$this->params['id']
访问 ID。编辑:
另外,请查看 将参数传递给操作。
可以将 ID 作为控制器操作的参数传递,如下所示:
然后您可以在
QuotesController::add($id)
中使用$id
访问 ID 。Have a look at the documentation for defining routes.
Something like this should do the trick:
You will be able to access the ID with
$this->params['id']
inQuotesController::add()
.Edit:
Also, have a look at the documentation for passing parameters to action.
It is possible to pass the ID in as a parameter of the controller action like so:
You can then access the ID with
$id
inQuotesController::add($id)
.