返回一个学说“find()”结果作为一个类
因此,我知道 Doctrine“find()”(Doctrine 2)调用的结果会生成基于 Doctrine 的类,但我试图通过 SOAP 连接仅输出相关数据(不要问)并且不希望所有 Doctrine 元数据也通过。
例如,我的 find('Account',1) 结果给了我一个类,其中包含名字、姓氏和电子邮件地址的属性。该类的属性也与硬件模型相关,让我可以利用那里的相关结果。不过,我想要返回的是这样的:
object(stdClass)#15 (5) {
["companyName"]=>
string(12) "test company"
["firstName"]=>
string(5) "chris"
["id"]=>
int(1)
["lastName"]=>
string(7) "smith"
["hardware"]=> array(
[0] => object(stdClass)#15 (5) {
["hostname"]=>
string(12) "host1",
[1] => object(stdClass)#16 (5) {
["hostname"]=>
string(12) "host2",
[2] => object(stdClass)#17 (5) {
["hostname"]=>
string(12) "host3"
)
似乎应该有一种自动方法来执行此类操作,因此我不必编写自定义过滤方法/类来删除我需要的数据。 Doctrine 开发者有什么建议吗?
So, I know that the result of a Doctrine "find()" (Doctrine 2) call results in a Doctrine-based class, but I'm trying to output just the relevant data back over a SOAP connection (don't ask) and don't want all of the Doctrine metadata to come through too.
For example, my result of a find('Account',1) gives me a class back with properties on it for firstName, lastName, and emailAddress. A property on the class also relates to the Hardware model and lets me tap into the associated results there. What I want to be returned, though, is something like:
object(stdClass)#15 (5) {
["companyName"]=>
string(12) "test company"
["firstName"]=>
string(5) "chris"
["id"]=>
int(1)
["lastName"]=>
string(7) "smith"
["hardware"]=> array(
[0] => object(stdClass)#15 (5) {
["hostname"]=>
string(12) "host1",
[1] => object(stdClass)#16 (5) {
["hostname"]=>
string(12) "host2",
[2] => object(stdClass)#17 (5) {
["hostname"]=>
string(12) "host3"
)
It seems like there should be an automatic way to do this sort of thing so I don't have to write a custom filtering method/class just to strip out the data I need. Any tips from Doctrine devs out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这可能是您正在寻找的东西:
但是您需要修改 where.
I think this might be something you are looking for:
But you need to modify the where.
尝试解开相关对象:
但是忘记标准类的东西,获取它的唯一方法是将对象转换为数组,然后将它们转换为对象。不管怎样,如果它是一个 SOAP 连接,我想你应该使用数组而不是对象。
Try to unwrap the related object:
But forget the standard class thing, the only way to get it is to convert your objects to an array and then cast them to objects. Anyway, if it's a SOAP connection, I suppose you should use arrays instead of objects.