Express Documentation... what am i missing?

Permalink
Hey all. I have this older block that lists locations (by states) on a illustrated (vector) map that I would like to update to use an express object to fill out the locations instead of the block's db tables.

I am following (or at least trying to) this documentation...https://documentation.concrete5.org/developers/express/creating-read...

So in my block's view function I have this.

$entity = Express::getObjectByHandle('member_listing');
if (is_object($entity)) {
   $list = new \Concrete\Core\Express\EntryList($entity);
   $results = $list->getResults();
   var_dump($results);
}


This unfortunately causes a memory allocation error. What am I missing??

 
hutman replied on at Permalink Reply
hutman
What you're trying to dump is a list of entities, so it's going to be a lot of information. Dumping it to the screen isn't really going to work.
Chrouglas replied on at Permalink Reply
Cool. So, in other words, I am doing it wrong. Thank you for your help... I'm not sure I even need to do this for my project but it is something I WANT to understand.

This is what sets which Data Object I want to get, correct?
$entity = Express::getObjectByHandle('should_this_be_singular_handle_or_plural_handle');

and this is the list of entries within the object?
$list = new Concrete\Core\Express\EntryList($entity);

then this is ?? another step? how's this different from $list by itself in the step above?
$students = $list->getResults();

at this point (in the documentation) it shows how you would filter the results. great but i dont need to at the moment. and then it goes into how to get a single entry by an ID. great again but, again, a different subject.

How do you go from $students to an array that can be iterated through in a for statement? The documentation skips over that.

I tried to dissect the Express list block and distill it down to just "get the object" and "display the info" but i continue to get errors.

Any help is greatly appreciated. I know that the people who post answers do so on their own time.
hutman replied on at Permalink Best Answer Reply
hutman
I understand your frustration, I'm sorry that this isn't better documented but the documentation is mostly written by community volunteers and there are just too many things to get it all documented.

Hopefully this will be helpful.


This gives you the entity: $entity = Express::getObjectByHandle('member_listing');
This gives you this list object: $list = new \Concrete\Core\Express\EntryList($entity);
This gives you the list results - which is an array of objects: $results = $list->getResults();

You can then loop over that array of objects and use them for whatever you need, since I don't know what the structure of your entities is I can't really help a whole lot, but that should explain the code you already have. As MrKDilkington says you can use var_dump_safe to see the individual results (within your foreach).

So something like this

$entity = Express::getObjectByHandle('member_listing');
if (is_object($entity)) {
   $list = new \Concrete\Core\Express\EntryList($entity);
   $students = $list->getResults();
   if($students){
      foreach($students as $student){
         var_dump_safe($student);
         //here you could also do things like echo $student->getStudentFirstName();
      }
   } else {
      echo 'No results';
   }
} else {
   echo '$entity is not an object';
}
Chrouglas replied on at Permalink Reply
Perfect thank you!!

And I was just about to ask if you happen to know how I would sort by the addresses sub-info (city, state, etc)... I was trying all sorts of weird variations to see if I could make that happen on my own. Tried one last shot in the dark literally as I was half way through typing this and it worked!! Apparently you just tack the sub-item (im sure there is a more correct name for that) onto the end of the parent in CamelCase.

where my attribute handle is 'member_address'
and I want to sort by state_province
$list->sortByMemberAddressStateProvince('asc');

Who knew? :) Anyway, now it is up for the next google search.
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi Chrouglas,

In addition to what hutman said, you can use var_dump_safe() to var_dump() Doctrine entities. The var_dump_safe() method is a Doctrine debug utility.
https://github.com/concrete5/concrete5/blob/3a1eb3373a108baeaa458b46...