Jig: Am I doing it right?

109 views
Skip to first unread message

Summer White

unread,
Nov 10, 2016, 9:24:42 PM11/10/16
to Fat-Free Framework
Learning Jig and how to use these mappers..

Getting data from DB into the hive for template use. I suspected that it might implement Traversable so I can could use foreach or <repeat> but it doesn't seem too.

Am I doing it right?

$mapper = new DB\Jig\Mapper($this->jig, "listings");
$mapper
->load();
       
while (!$mapper->dry())
{
    $f3
->push("listings", $mapper->cast());
    $mapper
->next();
}

ved

unread,
Nov 11, 2016, 3:40:53 AM11/11/16
to Fat-Free Framework
Not sure if what you're doing works, but seems like an unnecessary loop there.Try this:

$mapper = new DB\Jig\Mapper($this->jig, "listings");

$f3
->set("listings", $mapper->find());


Summer White

unread,
Nov 11, 2016, 6:03:30 PM11/11/16
to Fat-Free Framework
What I was doing does work, but really did seem like a lot of unnecessary function calls.

Cheers, this makes plenty more sense now.

Summer White

unread,
Nov 15, 2016, 10:16:15 PM11/15/16
to f3-fra...@googlegroups.com
I just revisited this code and using the find method returns an array with elements containing DB\Jig\Mapper objects.

This means I would still need to loop through and cast each to an array. How would this work in the template language with repeat?

Something like this?

<repeat group="{{@results}}" value="{{@row->cast()}}">

ikkez

unread,
Nov 16, 2016, 3:52:16 AM11/16/16
to Fat-Free Framework
You don't need to cast it to use it in the template. just work with those objects ;)
This also gives you the flexibility to add some extra model functions that you can use in the template directly.

<repeat group="{{@results}}" value="{{@mapper}}">

<h3>{{@mapper.title}}</h3>
<p>{{@mapper->getSummary()}}</p>

</repeat>

Summer White

unread,
Nov 17, 2016, 12:51:38 AM11/17/16
to Fat-Free Framework
I was wondering if foreach handled objects like that. But in retrospect its iterating through an array and just passing value an object. I hadn't wrapped my head around that part.

This makes me very happy though. Thank you!
Reply all
Reply to author
Forward
0 new messages