vanMeerdervoort
vanMeerdervoort

Reputation: 75

Illegal string offset in Fat Free Framework template

I fetch a result in Fat Free Framework with this:

$product = new DB\SQL\Mapper($db,'products');    
$product->load(array('productId=:ID',':ID'=>$productId));

Then I walk through $product using the dry() method and do some calculations to some of it's fields. I want to make the re-calculated content of the $product available in my template, so I do:

$f3->set('product_contents', $product);

Now, when in my template I do:

<repeat group ="{{@product_contents}}" value="{{@item}}">
   <p>{{@item.productName}}</p>
</repeat>

I get this error:

Internal Server Error
Illegal string offset 'productName'

I discovered that my {{@product_contents}} is a mapper object and not an array, hence the error.

The question is: how can I still use the contents of $product in my template in repeat groups?

Upvotes: 0

Views: 457

Answers (2)

JZILLA777
JZILLA777

Reputation: 41

Just load the result into a variable
$output = $product->load(array('productId=:ID',':ID'=>$productId));
$f3->set('product_contents', $output);

Upvotes: 0

xfra35
xfra35

Reputation: 3908

The cast() method is there to cast a mapper object to an array:

$f3->set('product_contents', $product->cast());

Upvotes: 1

Related Questions