锂形式助手不在字段中显示值零(0)

时间:2012-05-30 15:51:59

标签: php lithium formhelper

当使用Lithium框架开发PHP应用程序时,我注意到零值没有显示在表单的文本字段中。目前,我正在从MySQL数据库中获取数据,显示它并更新它。我能够将值零保存到数据库,并且从数据库返回的信息是正确的,因为我能够在将值直接回显到页面时查看它,并且正确显示除零以外的任何值。有没有人知道如何以锂的形式启用零值渲染,或者可能在使用Lithium渲染之前禁用值检查?

我在使用<?=$this->form->field...绑定到对象的表单中使用由锂提供的默认<?=$this->form->create($object); ?>

1 个答案:

答案 0 :(得分:2)

哈。我之前从未注意过。似乎应该修复它。

与此同时,您可以在应用中修改lithium\template\helper\Form或创建app\extensions\helper\Form(如果您使用应用的命名空间替换app,则可以使用默认app更改_defaults()

需要更改的方法是protected function _defaults($method, $name, $options) { $methodConfig = isset($this->_config[$method]) ? $this->_config[$method] : array(); $options += $methodConfig + $this->_config['base']; $options = $this->_generators($method, $name, $options); $hasValue = ( (!isset($options['value']) || $options['value'] === null) && $name && $value = $this->binding($name)->data ); $isZero = (isset($value) && ($value === 0 || $value === "0")); if ($hasValue || $isZero) { $options['value'] = $value; } if (isset($options['value']) && !$isZero) { $isZero = ($options['value'] === 0 || $options['value'] === "0"); } if (isset($options['default']) && empty($options['value']) && !$isZero) { $options['value'] = $options['default']; } unset($options['default']); $generator = $this->_config['attributes']['name']; $name = $generator($method, $name, $options); $tplKey = isset($options['template']) ? $options['template'] : $method; $template = isset($this->_templateMap[$tplKey]) ? $this->_templateMap[$tplKey] : $tplKey; return array($name, $options, $template); } 。以下是将显示零值的内容:

"0"

当前版本的某些条件因实际零整数或字符串{{1}}而失败。