我正在尝试将一个变量添加到链接<a href="foo.com/$ID">LINK</a>
的末尾。我正在使用Laravel,并将一组数据传递到视图,然后将其循环显示。
查看
<form action="{{ URL::route('Search')}}" method="get">
Search<input type="text" name="query" /><br>
<input type="submit" value="Search" />
{{Form::token()}}
</form>
<br>
<?php if (count($Results) > 0): ?>
<table style="border-collapse: separate; border-spacing: 25px 5px;">
<thead>
<tr>
<p></p><th><?php echo implode('</th><th>', array_keys(current($Results))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($Results as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td>
</tr>
<?php endforeach; ?>
<tbody>
</table>
<?php endif; ?>
显示。
title place_film_country wab_id
4th of February Sri Lanka 266
因此,我试图将wab_id转换为一个变量,并将其粘贴在链接的末尾。
控制器
public function Search(){
$query = Input::get('query');
$raw_results = DB::Table('films')->select('title', 'place_film_country', 'wab_id')
->where('title', 'LIKE', "%$query%")
->orwhere('place_film_country', 'LIKE', "%$query%")
->orwhere('genre', 'LIKE', "%$query%")
->orwhere('wab_id', 'LIKE', "%$query%")
->get();
$array = json_decode(json_encode($raw_results), true);
return View::make('Index')->with('Results', $array);
}
替换此:
<td><?php echo implode('</td><td>', $row); ?></td>
像这样的东西:
<td><?= $row['title'] ?></td>
<td><?= $row['place_film_country'] ?></td>
<td><a href="http://foo.com/<?= $row['wab_id'] ?>"><?= $row['wab_id'] ?></a></td>
您的问题有点令人困惑,但如果您有一个变量$ID
,并且您想将其附加到URL的末尾,则首先需要将其包装在php标记中,例如:
<a href="<?=URL("route/{$ID}")?>">LINK</a>
或者,如果您正在使用刀片:
<a href="{{URL("route/{$ID}")}}">LINK</a>
希望能有所帮助。