eZ Community » Forums » Developer » Fetch data from database using...
expandshrink

Fetch data from database using persistent object

Fetch data from database using persistent object

Monday 20 February 2012 5:46:08 pm

Hello,

I'm new to the eZComponents framework and I 'm using the Mvc Tools and persistent object to manipulate data from mysql. I can fetch an article getting the id from url using the following code:

    public function doArticle()
    {
        $ret = new ezcMvcResult;
       
        $session = ezcPersistentSessionInstance::get();
        $article = $session->load('Article', $this->id);
        $ret->variables['article'] = $article->getState();
        return $ret;
    }

 

However I cannot list my articles! Can someone help me with this code:

controller.php

    public function doHome()
    {
        $ret = new ezcMvcResult;
       
        $session = ezcPersistentSessionInstance::get();
        $q = $session->createFindQuery('Article');
        $objects = $session->findIterator($q, 'Article');
       
        foreach ( $objects as $object )
        {
            $ret->variables['articles'] = $objects;
        }
        return $ret;
    }

 

template file:

{use $articles}
{foreach $articles as $article}
    {$article['title']}<br>{$article['body']}<br><br>
{/foreach}

 

Thank you in advance

Modified on Monday 20 February 2012 5:55:51 pm by Matthieu Kapetanos

No reply yet!

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from