Samia Ruponti Samia Ruponti - 4 years ago 235
PHP Question

symfony2 php access object of another entity

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download