【发布时间】:2012-05-15 18:22:25
【问题描述】:
我有以下代码:
<?php
$select_options = array();
foreach($delivery_options as $option)
{
$select_options[$option->getDeviceId()] = $option->getDeviceName();
echo $select_options[$option->getDeviceId()];
}
echo $this->Form->input('default_device', array(
'type' => 'select',
'options' => $select_options,
'value' => $default_device,
'label' => '',
));
?>
在 foreach 循环中,每个回显都会返回:
abc'abc
在 html 源代码中它看起来像这样 abc&amp;#39;abc
然后在选择输入:abc&amp;#39;abc
html源代码中:abc&amp;#39;abc
这意味着 abc&amp;#39;abc 中的 & 字符被转换为它的 html 编码 - &amp - 但它是怎么发生的?
我也尝试了 htmlentities() 和 htmlspecialchars() 但这仍然没有帮助...
【问题讨论】:
-
在这样的输入中使用值是错误的。您销毁帖子上的表格(它会一直重置)。使用“默认”正确设置默认值,或者使用控制器更好地设置默认值 - 请参阅dereuromark.de/2010/06/23/working-with-forms
-
true,但在这种情况下,
$default_device不是选择的默认值,而是用户的默认设备 - 我从$this-Auth-user('default_device')读取它...
标签: html cakephp encoding cakephp-2.0