我有一个Zend表单,它允许您向数据库中添加大学班级。我收集数据并使用Doctrine 2持久化它。一切都很好,数据在表中。当我检索数据时,一切都已准备就绪。
array
0 => &
array
'id' => int 151
'className' => string 'Geocaching (Jee-oh-Cash-ing) is part of a worldwide outdoor game for GPS users. Go on an adventure to find hidden treasure, called “geocaches”. If you own a GPS receiver or a smartphone, bring it (preferred, but not required) along with some fresh batteri' (length=255)
'instructor' => string 'Geocaching (Jee-oh-Cash-ing) is part of a worldwide outdoor game for GPS users. Go on an adventure to find hidden treasure, called “geocaches”. If you own a GPS receiver or a smartphone, bring it (preferred, but not required) along with some fresh batteri' (length=255)
'classDescription' => string 'Geocaching (Jee-oh-Cash-ing) is part of a worldwide outdoor game for GPS users. Go on an adventure to find hidden treasure, called “geocaches”. If you own a GPS receiver or a smartphone, bring it (preferred, but not required) along with some fresh batteri' (length=255)然后我使用Jquery DataTables来显示所有的表数据。我有一个为datatable呈现jquery的视图帮助器。在我使用的视图帮助器内部
Zend_Json::encode(array_merge($this->_defaultOptions, $options), false, array('enableJsonExprFinder' => true)); 所有包含双引号的值都将编码为null。
"aaData":{"id":151,"className":null,"instructor":null,"classDescription":null,}}'除带有双引号的任何值外,任何其他值都将显示在DataTable中。
我一定是做错了什么,因为当我试图用数据重新填充Zend表单以进行更新时,我也遇到了这个问题。
$results = $this->_doctrine->getEntityManager()->getRepository('My\Entity')->findOneBy($request->getParam('id'));
$form->setDefaults($results[0]);同样,如果我转储Doctrine的结果,所有引用的数据都在那里,可以使用。但是在$ form ->setDefaults($results)之后,表单中的字段是空白的。
任何帮助都是非常感谢的。
发布于 2013-04-10 01:43:10
我也有同样的问题。解决方案是引号不是“而是”(微软编码的引号),这导致json_encode()返回null。用这个答案中的方法(How to replace Microsoft-encoded quotes in PHP)替换解决了这个问题。
更新:
Zend还有一个编码器,可以为您解析字符串。但是您需要在引导程序中设置Zend_Json::$userBuiltinEncoderDecoder = true,然后它将使用它而不是php的json_encode
发布于 2012-02-15 12:47:55
我认为您需要使用常量JSON_HEX_QUOT
这似乎起作用了:
$options = array(JSON_HEX_QUOT);
$json = Zend_JSON($value, $cyclecheck, $options);我深入研究了Zend/Json.php代码,看起来如果您想要使用JSON_HEX_QUOT,就必须使用PHP函数,因为Zend_Json不会传递常量。
// Encoding
if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
$encodedResult = json_encode($valueToEncode);我认为这是因为ZF是按照PHP5.2.6标准编写的,而$options是在PHP5.3.0中添加到json_encode中的
下面是php手册中的参考:
示例#2 *显示所有实际选项的json_encode()示例*
<?php $a = array('<foo>',"'bar'",'"baz"','&blong&');
echo“正常:",json_encode($a),"\n";echo”标签:",
json_encode($a,JSON_HEX_TAG),"\n";echo "Apos:",
json_encode($a,JSON_HEX_APOS),"\n";echo“报价:",
json_encode($a,JSON_HEX_QUOT),"\n";echo "Amp:",
json_encode($a,JSON_HEX_AMP),"\n";echo "All:",
JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP),( json_encode($a,$a "\n\n";
$b =数组();
echo“空数组输出为数组:",json_encode($b),"\n";echo”空数组输出为对象:",json_encode($b,JSON_FORCE_OBJECT),"\n\n";
$c =数组(数组(1,2,3));
echo“非关联数组输出为数组:",json_encode($c),"\n";echo”非关联数组输出为对象:",json_encode($c,JSON_FORCE_OBJECT),"\n\n";
数组= $d (‘foo’=> 'bar','baz‘=> 'long');
echo“关联数组始终输出为对象:",json_encode($d),"\n";echo”关联数组始终输出为对象:",json_encode($d,JSON_FORCE_OBJECT),"\n\n";
https://stackoverflow.com/questions/9284629
复制相似问题