将两个值传递给嵌套的 restful 控制器 [英] Passing two values to the nested restful controller

查看:31
本文介绍了将两个值传递给嵌套的 restful 控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我嵌套的 restful 控制器中,我的 show 方法应该接收两个这样的值

In my nested restful controller my show method should receives two values like this

public function show($postId, $commentsId)
{

// code

}

生成的url应该是这样的

the generated url should be like this

http://localhost/posts/1/comments/1

现在我的查询是:我需要通过路由调用发送那些 twu 值

Now my query is: I need to send those twu value through my route call

我是这样使用的:

<a href="{{ URL::route('posts.comments.show', value1, value2) }}"> <h3> Click </h3></a>

但它给出了这样的错误

Symfony \ Component \ Routing \ Exception \ InvalidParameterException
Parameter "dcoms" for route "debates.dcoms.show" must match "[^/]++" ("" given) to generate a corresponding URL.

推荐答案

现在这个问题解决了.我在这里添加这个答案,因为它可能会帮助您解决此类问题.我要感谢 @FDL 的大力支持,还要感谢 @kasys.

Now this problem is solved. I am adding this answer here cause It might help you to solve this type of problem. I want to thank @FDL for his awesome support and also to @kasys .

我在那里犯了一个错误,因为我在对@kasys(@FDL 解决了这个问题)的评论中猜到了生成 URL.

I had done a single mistake there as I have guessed in comment to the @kasys (@FDL solved this) in generating the url.

这种情况下url生成方法应该是这样的

In this case the url generating method should be like this

<a href="{{ URL::route('posts.comments.show', array(value1, value 2)) }}"><h3>Click this link</h3></a>

这里的 value1 表示帖子的 id,value2 表示评论的 id,因此此链接生成的 url 为 ->

here the value1 means the id of posts and value2 means the id of comments so url would be generated by this link is as ->

http://localhost/posts/value1/comments/value2

感谢@FDL 和所有参与这里的恶魔.很快,一个网站将震撼世界.需要你的祝福的朋友:) 谢谢!

Thank you @FDL and all those fiends who have participated here. Soon a website will come to rock the world. need your blessings friends :) Thanks !

这篇关于将两个值传递给嵌套的 restful 控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆