doukeng7426
2018-04-11 10:37
浏览 45
已采纳

php - 如何在刀片中设置href url

I'm currently working with Laravel (because my school told me to) and php and I really don't get it. I'm working with blade.php which recieves values from a ViewControlle(not quite if it works like this but I think so). The value contains name and and a url for wikipedia which leads to the right article for the name in a table.

So what I'm trying to accomplish is

<a href="https://en.wikipedia.org/wiki/Berlin">Berlin</a>

So my code is currently:

@foreach($cities as $city)
<td>
<tr><a href="{{$city["Url"]}}">{{$city["Name"]}}</a></tr>
</td>
@endforeach

and it does not work while

@foreach($cities as $city)
<td>
<tr>{{$city["Name"]}}</tr>
</td>
@endforeach

works perfectly fine...

I've already searched for an answer but all answers are written for php with

echo '...';

I really don't get it.

Thanks in advance ^^

图片转代码服务由CSDN问答提供 功能建议

我目前正在使用 Laravel (因为我的学校告诉我)和php 而且我真的不明白。 我正在使用 blade.php 从ViewControlle 接收值(如果它的工作方式如此,那就不一定了,但我认为如此 )。 值包含名称和维基百科的网址,这会在表格中显示正确的文章名称。

所以我想要完成的是

 &lt; a href =“https://en.wikipedia.org/wiki/Berlin”&gt; 柏林&lt; / a&gt; 
   
 
 

所以我的代码目前是:

  @  foreach($ cities as $ city)
&lt; td&gt; 
&lt; tr&gt;&lt; a href =“{{$ city [”Url“]}}”&gt; {{$ city [“Name”]}}&lt;  ; / a&gt;&lt; / tr&gt; 
&lt; / td&gt; 
 @ endforeach 
   
 
 

<时不起作用 / p>

  @foreach($ cities as $ city)
&lt; td&gt; 
&lt; tr&gt; {{$ city [“Name”]}}&lt; / tr&gt; 
&lt  ; / td&gt; 
 @ endforeach 
   
 
 

完美无缺...

我已经搜索过答案 但所有的答案都是用php编写的

  echo'...'; 
   
 
 

我真的不喜欢 得到它。

提前致谢^^

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongmi4809 2018-04-11 11:04
    已采纳

    change

    <tr><a href="{{$city["Url"]}}">{{$city["Name"]}}</a></tr>
    

    to

     <tr><a href="{{$city['Url']}}">{{$city["Name"]}}</a></tr>
    

    or you can do it like this:

    <tr><a href='{{$city["Url"]}}'>{{$city["Name"]}}</a></tr>
    
    打赏 评论
  • dongyiba8082 2018-04-11 10:59
    @foreach($cities as $city)
        <td>
            <tr>
                <a href="{{ $city->Url }}">{{ $city->Name }}</a>
            </tr>
        </td>
    @endforeach
    
    打赏 评论

相关推荐 更多相似问题