Laravel刀片模板,URL :: to内的foreach变量?
我正在创建帖子的基本列表视图,并且需要指向编辑"页面的链接.
I'm creating a basic list view of posts, and need a link to the 'edit' page.
我使用的是Blade,我有一张桌子,上面有一个foreach循环,显示了每个帖子以及编辑/删除按钮.
I'm using blade, and what I have is a table, with a foreach loop, showing each post along with edit/delete buttons.
我想做的是使用Blade的URL :: to指向编辑和删除页面的链接,以确保链接一致.
What I wanted to do is use blade's URL::to for the links to the edit and delete pages, to ensure consistant links.
我尝试使用的代码(记住这是在foreach循环内,因此$ post-> id var)是这样的:
The code I've tried using (remember this is inside a foreach loop hence the $post->id var) is this:
<a href="{{ URL::to('admin/posts/edit/$post->id') }}" class="btn btn-mini btn-primary">Edit Post</a>
但是,这不起作用.我也尝试过
However this does not work. I've also tried
<a href="{{ URL::to('admin/posts/edit/<?php echo $post->id; ?>') }}" class="btn btn-mini btn-primary">Edit Post</a>
这也不起作用.
我没有收到任何错误,链接字面意思是:
I dont get any error, the link literally ends up being:
http://domain.dev/admin/posts/$post->id
有什么办法解决这个问题?
Is there any way of working around this?
我认为问题在于,您正在使用带有单个'
的字符串中的php变量($ post).在这种情况下,它仅输出变量的名称.试试这个:
I think the problem is that you are using php variable ($post) within a string with a single '
. In this case it just outputs the name of the variable. Try this:
<a href="{{ URL::to('admin/posts/edit/' . $post->id) }}" class="btn btn-mini btn-primary">Edit Post</a>
希望这会有所帮助. 弗拉德
Hope this helps. Vlad