我有一个简单的代码,当我print_r
时,这个是输出:
Array
(
[0] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10025
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:33:59.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc@gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[1] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10026
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:36:03.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc@gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
[2] => App\Entities\EibPerson Object
(
[personId:App\Entities\EibPerson:private] => 10027
[createdBy:App\Entities\EibPerson:private] => 1
[createdOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[modifiedBy:App\Entities\EibPerson:private] => 1
[modifiedOn:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 2016-12-06 08:37:25.000000
[timezone_type] => 1
[timezone] => +03:00
)
[recordVersion:App\Entities\EibPerson:private] => 1
[activeFlag:App\Entities\EibPerson:private] => 1
[firstName:App\Entities\EibPerson:private] => test person name
[middleName:App\Entities\EibPerson:private] => test middle
[lastName:App\Entities\EibPerson:private] => test last name
[displayName:App\Entities\EibPerson:private] => sorxrob
[dateOfBirth:App\Entities\EibPerson:private] => DateTime Object
(
[date] => 1992-10-01 03:00:00.000000
[timezone_type] => 1
[timezone] => +03:00
)
[landlineNumber:App\Entities\EibPerson:private] => 2312321313131
[mobileNumber:App\Entities\EibPerson:private] => 876543454
[emailAddress:App\Entities\EibPerson:private] => sorianorobertc@gmail.com
[heightInches:App\Entities\EibPerson:private] => 6
[inseamLengthInches:App\Entities\EibPerson:private] => 6
[weightInKgs:App\Entities\EibPerson:private] => 80.00
[profilePictureUrl:App\Entities\EibPerson:private] =>
[sourceDesc:App\Entities\EibPerson:private] => testsourceDesc
[remarks:App\Entities\EibPerson:private] => test remarks test
[memberId:App\Entities\EibPerson:private] =>
[externalReferenceId:App\Entities\EibPerson:private] =>
[genderEnumRid:App\Entities\EibPerson:private] =>
[address:App\Entities\EibPerson:private] =>
[tshirtSizeEnumRid:App\Entities\EibPerson:private] =>
[bloodGroupEnumRid:App\Entities\EibPerson:private] =>
[managingBranch:App\Entities\EibPerson:private] =>
[foodPreferenceEnumRid:App\Entities\EibPerson:private] =>
[sourceEnumRid:App\Entities\EibPerson:private] =>
[sourceDetailRid:App\Entities\EibPerson:private] =>
[externalSourceSysEnumRid:App\Entities\EibPerson:private] =>
)
)
我的代码:
$person = $this->em->getRepository('App\Entities\EibPerson')->findAll();
print_r($person);
我真正想要的只是得到这个:
我怎么可能这样做?因为我想json_encode数组但我得到一个空的json ..
答案 0 :(得分:0)
使用最大深度进行调试
您可以使用Doctrine Dump的maxDepth变量。
您可以使用\Doctrine\Common\Util\Debug::dump($variable, $depth);
显示没有代理信息的doctrine输出。
更易读的输出
如果您使用的是symfony 2.6或更高版本,我强烈建议您使用dump()
代替var_dump()
或print_r()
。
转储显示格式良好的彩色输出,您可以展开/隐藏行。
最后......到json
要将对象导出到json,我建议你使用序列化器和规范化器服务,你可以找到here in the documentation