这些数据在何处以及如何更改?

时间:2014-06-11 16:51:09

标签: laravel-4 eloquent

以下代码可以正常工作,除了在一个实例中发生了一些“清理”数据而不是另一个我无法破译的数据。

我有一个表(clientdocs),其字段'from'包含以下格式的字符串数据:

Richard Robinson <richard@gmail.com>

在我的控制器中,我有代码为此表中的下拉列表构建一个数组:

// get clients
$sender_sel = array('Any Sender');

$senders = Clientdoc::orderBy('from', 'ASC')
    ->distinct()
    ->get( array('from') );

foreach($senders as $sender) {
    $sender_sel[] = $sender->from;
}

我还从表中检索所有数据并将其传递给视图(以及上面的数组和其他内容):

return View::make('clientdocs/index')
    ->with('date_sel', $date_sel)
    ->with('sender_sel', $sender_sel)
    ->with('docs', Clientdoc::orderBy('date_emailed', 'ASC')->get());

现在,在我看来:

我使用$ sender_sel作为:

{{ Form::select('from', $sender_sel, '', array(
'class' => 'form-control'
)) }}

并按预期显示:

"Richard Robinson <richard@gmail.com>"

我还使用第二个查询(docs对象)中的数据:

<table class="table table-striped table-hover">
    <tr>
        <th>Date</th>
        <th>From</th>
        <th>Type</th>
    </tr>
    @foreach ($docs as $doc)
        <?php $detail_url = 'clientdocs/' . $doc->id . '/edit' ; ?>
        <tr>
            <td>{{ $doc->from }}</td>
        </tr>                       
    @endforeach
</table>

以下是踢球者:$ docs-&gt;来自显示为

"Richard Robinson", without the "<richard@gmail.com>"

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

查看来源。它仍然存在,但<>是HTML中的特殊字符(因为它们在HTML标记中使用)。

使用三重括号可以转义Blade中的输出,因此{{{ $doc->from }}}会将其转换为&lt;&gt;来修复它。