1

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

public function show($postId, $commentsId)
{

// code

}

生成的url应该是这样的

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

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

我这样使用:

<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.
4

2 回答 2

0

你可以通过声明额外的路线来做到这一点。

你应该有这样的东西:

Route::controller('posts', 'RestController');

尝试添加以下行:

Route::controller('posts/{postId}/comments/{commentsId}', 'RestController@anotherShow');

在您的函数内部,您必须为此路线添加函数:

public function anotherShow($postId, $commentsId)
{

    // code

}

你也改变了URL::route这样的:

URL::route('posts.comments.show', array(value1, value2))

或者:

URL::route('posts.comments.show', array('postId'=>value1, 'commentsId'=>value2))
于 2013-11-06T10:56:24.180 回答
0

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

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

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

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

这里的value1意思是帖子value2的id和评论的id,所以这个链接生成的url是->

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

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

于 2013-11-06T11:40:41.513 回答