XF 2.0 Forcing specific array keys in template foreach?

Jaxel

Well-known member
This is what I am doing:
Code:
        $articles = $entries->fetch();
        $entriesC = $this->getCatLinkRepo()->findCatLink()
            ->where('thread_id', array_keys($articles->toArray()))
            ->fetch();
        
        $catlinks = [];
        foreach ($entriesC AS $catlink)
        {
            $catlinks[$catlink->thread_id][$catlink->category_id] = $catlink;
        }
        
        $viewParams = [
            'articles' => $articles,
            'catlinks' => $catlinks,
        ];

I am then trying to access the `$catlinks` in my template on a per `$article` basis:
Code:
<xf:foreach loop="$catlinks.{$article.thread_id}" value="$catlink">

Unfortunately, this is giving me an error.
 
Might come in handy sometime:
You can call groupBy('someKey') on an array collection (the thingy you get when you call fetch()) to automatically group them by a specific key.
 
Might come in handy sometime:
You can call groupBy('someKey') on an array collection (the thingy you get when you call fetch()) to automatically group them by a specific key.
I was thinking of using that... But unfortunately it would add an extra query per article until the TO_MANY property is functional.
 
Back
Top Bottom