Getting Associated Entries | express_entry_list -> template -> boats.php

Permalink
I created Express Data Objects and entered all the data through the interface. I also made the one to many Associations. Now I need to output it all in my template. What is the right code for the boat location (MarinaName)?

<?php
   $boatImage = $item->getEntry()->getBoatImage();
   if (is_object($boatImage)) { ?>
      <img src="<?php echo $boatImage->getRelativePath(); ?>" alt="">
   <?php } ?>
<h3><?=$item->getEntry()->getBoatName();?></h3>
<h4><?=$item->getEntry()->getBoatDescription();?></h4>
<p>Stock: <?=$item->getEntry()->getBoatStock();?></p>
<p>Fuel Type: <?=$item->getEntry()->getBoatFuelType();?></p>
<p>Color: <?=$item->getEntry()->getBoatColor();?></p>
<p>Location: <?=$item->getEntry()->getMarinaName();?></p>

View Replies:
hutman replied on at Permalink Reply
hutman
Can you give us some more background about the entities and the relationships?
lukrecija replied on at Permalink Reply
I followed exactly what Andrew did in the videos:
https://documentation.concrete5.org/developers/express/creating-expr...
https://documentation.concrete5.org/developers/express/using-the-exp...

But his example shows how to do the express_entry_detail page template.

My situation is very similar to the website he did for the salon. There is stylist page where it lists all the stylists and the locations associated to them (http://www.gingersalon.com/stylists).
https://documentation.concrete5.org/developers/express/overview...
hutman replied on at Permalink Reply
hutman
From that video and no background about what you actually setup it looks like you should be able to do $item->getLocations(); which will return you the location object and you can do a foreach loop on the locations to output the information.
lukrecija replied on at Permalink Reply
Thank you @hutman for the help. I still need guidance on this. $item->getLocations(); (in my case, $item->getMarinaName();) didn’t work. Here is some more background.
Boat have the fields “Name”->BoatName (text), “Description”->BoatDescription (textarea), “Stock”->BoatStock (number), “Fuel Type“->BoatFuelType (select), “Color“->BoatColor (select). I made the association many to one to the Marina object.
Marina have one field "Name"->MarinaName (text). Marina is related to a Boat through a one to many connection.

I have created the forms. For Boat form I have 2 field sets: Basics (name, description, stock, fuel type and color) and Marina association as a second set.

For Marina form, I have name and the boat association.

What is the php to pull the marina association on the boats page?
hutman replied on at Permalink Reply
hutman
I believe it should be

$item->getMarina()->getName();
lukrecija replied on at Permalink Reply
So the difference for the associated object is getMarina vs getEntry.
<p>Color: <?=$item->getEntry()->getBoatColor();?></p>
<p>Location: <?=$item->getMarina()->getMarinaName();?></p>

Also I thought that I need getMarinaName(); (handle is marina_name) vs getName();?

Unfortunately both ways I am getting an error: Call to undefined method Concrete\Core\Express\Entry\Search\Result\Item::getMarina()
hutman replied on at Permalink Reply
hutman
Just so I'm understanding what is your $item? Is it a Boat or is it a Marina?

I'm wondering if you don't have to do

$item->getEntry()->getMarina()->getMarinaName();
lukrecija replied on at Permalink Reply 1 Attachment
My $item is Boat. I am able to output all boat attributes (name, photo, description) to front-end, but not the associated object, which is Marina. See the screenshot for more clarification.

I am still getting an error for $item->getEntry()->getMarina()->getMarinaName();
Call to undefined method Concrete\Core\Entity\Attribute\Value\Value\SelectValue::getMarinaName()
hutman replied on at Permalink Reply
hutman
I'm sorry, I don't know what to tell you. Without having access to your setup I can't make any more suggestions.