cakephp 2.X 换行符不工作
cakephp 2.X newline not working
我试过使用 html br 标签,“\r\n”和 PHP_EOL 但是我的 table 数据不会换行。我不明白为什么它只是将它附加到一行而不是给一个回车 return.
这是它当前如何显示我的数据的图像:
<table>
<tr>
<th>Article</th>
<th>Action</th>
</tr>
<?php
foreach ($posts as $post):
?>
<tr>
<td>
<?php
echo $this->Html->link($this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - " . $post['Post']['article_title']
. PHP_EOL . "<br />\n" . "\r\n"
. $post['Post']['article_link'], array(
'controller' => 'posts',
'action' => 'view',
'inline' => false,
'escape' => false,
$post['Post']['id']
));
?>
</td>
<td>
<?php
echo $this->Html->link('Edit', array(
'action' => 'edit',
$post['Post']['id']
));
?>
<?php
echo $this->Form->postLink('Delete', array(
'action' => 'delete',
$post['Post']['id']
), array(
'confirm' => 'Are you sure?'
));
?>
</td>
</tr>
<?php
endforeach;
?>
<?php
unset($post);
?>
</table>
将 'escape' => false
添加到 link 选项以转义 html 个字符。这将允许您使用 <br>
.
echo $this->Html->link($this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - " . $post['Post']['article_title']
. PHP_EOL . "<br />\n" . "\r\n"
. $post['Post']['article_link'],
array(
'controller' => 'posts',
'action' => 'view',
'inline' => false,
'escape' => false, // move this
$post['Post']['id']
),
array(
'escape' => false // to here
)
);
像escape
这样的选项需要在HtmlHelper::link()
的$options
参数中传递,即第三个参数。第二个参数是 ment 仅用于 URL。
另请注意,当您禁用自动转义时,您应该手动对相关部分进行转义以避免XSS。
echo $this->Html->link(
$this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - "
. h($post['Post']['article_title']) // escape manually
. "<br />"
. h($post['Post']['article_link']), // escape manually
array(
'controller' => 'posts',
'action' => 'view',
$post['Post']['id']
),
array(
'inline' => false,
'escape' => false
)
);
另见 Cookbook > Core Libraries > Helpers > Html > HtmlHelper::link()
我试过使用 html br 标签,“\r\n”和 PHP_EOL 但是我的 table 数据不会换行。我不明白为什么它只是将它附加到一行而不是给一个回车 return.
这是它当前如何显示我的数据的图像:
<table>
<tr>
<th>Article</th>
<th>Action</th>
</tr>
<?php
foreach ($posts as $post):
?>
<tr>
<td>
<?php
echo $this->Html->link($this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - " . $post['Post']['article_title']
. PHP_EOL . "<br />\n" . "\r\n"
. $post['Post']['article_link'], array(
'controller' => 'posts',
'action' => 'view',
'inline' => false,
'escape' => false,
$post['Post']['id']
));
?>
</td>
<td>
<?php
echo $this->Html->link('Edit', array(
'action' => 'edit',
$post['Post']['id']
));
?>
<?php
echo $this->Form->postLink('Delete', array(
'action' => 'delete',
$post['Post']['id']
), array(
'confirm' => 'Are you sure?'
));
?>
</td>
</tr>
<?php
endforeach;
?>
<?php
unset($post);
?>
</table>
将 'escape' => false
添加到 link 选项以转义 html 个字符。这将允许您使用 <br>
.
echo $this->Html->link($this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - " . $post['Post']['article_title']
. PHP_EOL . "<br />\n" . "\r\n"
. $post['Post']['article_link'],
array(
'controller' => 'posts',
'action' => 'view',
'inline' => false,
'escape' => false, // move this
$post['Post']['id']
),
array(
'escape' => false // to here
)
);
像escape
这样的选项需要在HtmlHelper::link()
的$options
参数中传递,即第三个参数。第二个参数是 ment 仅用于 URL。
另请注意,当您禁用自动转义时,您应该手动对相关部分进行转义以避免XSS。
echo $this->Html->link(
$this->Time->format($post['Post']['created'], '%d %b %Y', 'invalid')
. " - "
. h($post['Post']['article_title']) // escape manually
. "<br />"
. h($post['Post']['article_link']), // escape manually
array(
'controller' => 'posts',
'action' => 'view',
$post['Post']['id']
),
array(
'inline' => false,
'escape' => false
)
);
另见 Cookbook > Core Libraries > Helpers > Html > HtmlHelper::link()