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?

  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘