It’s not possible to be sure from your explanation. But it is possible that product_details has been returned as an array of entities. If so, you would need something like this:
Where did this data format come from? I cannot make sense of what it’s trying to tell me. And I don’t see how you get from contain(['OrderProducts']) to something that has “product_details” in it instead of “order_products”.
thank you for the pinpoint, ya, i have made typo error when making the example resulting the confusion, i have edited the question and it should be clearer
thank you and await for your advise and guidance (thank you very much)
$order->$order is not something that is ever going to work. If you have $x = 'foo', then $order->$x is equivalent to referencing the property with the name that’s stored in $x, i.e. $order->foo. But it really only works if $x is a string. We know that $order is an object, so trying to use it as a property reference is nonsensical.
Hope that makes some sense; it’s a complicated topic.
$allorders is an array of Order entity objects. Each foreach iteration you’re putting one of them into $order
$order is therefore an Order entity object, whose contents can be accessed either by $entity->field or $entity[“field”] (the second is really syntactic sugar for the first, it’s not really an array)
If Order hasMany OrderProduct (which I deduce from your json-like data), the $order field order_products will be an array of OrderProduct entity objects, whose fields can be accessed as above.
Nested arrays are quite common in CakePHP as the ORM makes it easy to denormalize entities. So you just have to keep clear what’s happening.
A very good tool is the debugger toolbar - click the icon on the bottom right, one of the tabs lets you explore all of the variables in the view. This is useful when you don’t have a debugger.
ya, it works with $order->order_products[0]->product_name, the homework assignment which i am working on has many hasMany with id and id linking to other Controllers,
now learning how to call from another Controller and link to this controller.
thank you very much for the explanation, the debugger toolbar is nice, the bottom right corner one,