Adding to a multidimensional array

nrep

Well-known member
I'm coding an XF2 addon that will fetch a list of the last 10 resources entries, but also allow me to access the message content of each (so I can provide a teaser snippet). I've got the code to get the last 10 XFRM entries, but I'm struggling on how to add to the array to provide me with the message content. Here's my code so far:

PHP:
        $reviews = \XF::finder('XFRM:ResourceItem')->order('last_update', 'DESC')->fetch(max(0, 10));
        
        foreach ($reviews AS $id => $review)
        {
            $resourcemessage = $db->fetchOne("
            SELECT message
            FROM xf_rm_resource_update
            WHERE resource_id = ?
            ORDER BY resource_update_id DESC
            ", $review->resource_id);
            
            $reviews[$id]['message'] = $resourcemessage;
        }

However, when I try it, this is the error I get:

InvalidArgumentException: Column 'message' is unknown in src\XF\Mvc\Entity\Entity.php at line 582

How should I add to the array so that I can add the message variable?
 
Get the resources with "Description".

$reviews = \XF::finder('XFRM:ResourceItem')->with('Description')->order('last_update', 'DESC')->fetch(max(0, 10));

The message will be in the the Description->message field for each resource.
 
What I gave will give you the resource description and it just dawned on me that you might want to have a snippet of the last update message and not the resource description. If that's the case, your finder should be on the resource update entity.

$reviews = \XF::finder('XFRM:ResourceUpdate')->with('Resource')->order('post_date', 'DESC')->fetch(max(0, 10));

And the message will be in $reviews->message and the resource info will be in $reviews->Resource-><FieldName>.
 
Oh that may be handy to use! Thanks :). It appeared to work when I used your first snippet, but it may be better if I use the 2nd method.
 
Back
Top Bottom