0

I'm new to the eZComponents framework and I 'm using the Mvc Tools and persistent object to manipulate data from mysql.

I can get a single product on a page but I cannot list my products! Can someone help me with this code:

controller.php

public function doListproducts()
    {
        $ret = new ezcMvcResult;

        $session = ezcPersistentSessionInstance::get();
        $q = $session->createFindQuery('Product');
        $objects = $session->findIterator($q, 'Product');
        //$objects = $session->find($q, 'Product');

        foreach ( $objects as $object )
        {
            $ret->variables['products'] = $object;
            //$ret->variables['products'] = $object->getState();
        }
        return $ret;
    }

template:

{use $products}
{foreach $products as $product}
    {$article['product']}<br>{$product['body']}<br><br>
{/foreach}

The comments are different solutions but don't work either. Thanks for your help

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
MatthewK
  • 466
  • 4
  • 9
  • 19

1 Answers1

0
{foreach $productsas $product}

Should be:

{foreach $products as $product}

Also:

{$article['product']}<br>{$product['body']}<br><br>

What is $article ?

Finally, did you check that $ret has the expected value ?

jpic
  • 32,891
  • 5
  • 112
  • 113
  • No that was just a mistype. I changed to {$product->title} and worked! I don't understand the difference... Thank you anyway. – MatthewK Feb 24 '12 at 19:49
  • You don't understand the difference between what and what ? You should paste working code when you ask for support BTW – jpic Feb 24 '12 at 22:51
  • Difference is that `$product` is an object and `title` an attribute of this object. So you need to write `{$product->title}` If `$product` was an array or a hash and if `title` was a key, then you would have to write `{$product['title']}` – Charles-Édouard Coste Dec 10 '12 at 10:59