dqpkea9486
2016-02-16 05:39
浏览 40
已采纳

symfony2 php访问另一个实体的对象

I know its very lame question to ask. I have One Entity ContentSelector and another is Content in Content Selector I have a property Content where I have Id. I am trying to access the Content propety but always getting error. This is what I am trying to do.

$cs = $pages->getContentSelector();

it returns:

[

{
    "id": ​22,
    "title": "my Title",
    "content": "11021,10930,10874,10766,10954,10705,10948,10934,11048,11049,10831"
}

]

now I want to get the content property like $cs->content getting error like:

"Notice: Undefined property: Doctrine\\ORM\\PersistentCollection::$content"

tried with getContent(); getting error that the method doesnt exist. but in ContentSelector the method actually exists.

how can I easily get the content ids?

图片转代码服务由CSDN问答提供 功能建议

我知道这是一个非常蹩脚的问题。 我有一个实体ContentSelector,另一个是内容选择器中的内容我有一个属性内容,我有Id。 我正在尝试访问Content propety但总是收到错误。 这就是我想要做的。

  $ cs = $ pages-> getContentSelector(); 
   
 
 <  p>它返回: 
 
 
  [
 
 {
“id”:22,
“title”:“my title”,
“content”  :“11021,10930,10874,10766,10954,10705,10948,10934,11048,11049,10831”
} 
 
] 
   
 
 

现在 我想得到像 $ cs-&gt; content 这样的内容属性,如:

 “注意:未定义的属性:Doctrine \\ ORM \  \ PersistentCollection :: $ content“
   
 
 

尝试使用getContent(); 得到该方法不存在的错误。 但在ContentSelector中,该方法实际存在。

如何轻松获取内容ID?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglian2106 2016-02-16 05:54
    已采纳

    The getContentSelector() method return an ArrayCollection so you need to access to an element of the collection before call a method of the contained object. As example, you can access to the first element as follow:

    $collection = $pages->getContentSelector();
    $cs = $collection->first();
    

    Then you can try access to the objet element (from the dump seems a json object?)

    Hope this help

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题