Work with files

Hi @asmecher,

I was trying it before with this, so I’m aim on that again :). I have a little problem, when I’m change the script for

PublishedArticleDAO and using getPublishedArticle() to get articles, my code is:
    $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
    $articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
    import('classes.file.ArticleFileManager');
        
    $articles = $publishedArticleDao->getPublishedArticles($issueId);
    var_dump($articles);
    while ($article =&  $articles->next()) {                    // row 1124

I’m getting error

Fatal error: Call to a member function next() on a non-object in C:\xampp\htdocs\ojs245\pages\editor\IssueManagementHandler.inc.php on line 1124

But I don’t understand why - $articles is an array and $article is object, like in previous example with ArticleDAO. When I tried this:

$article =&  next(articles)

I get every article except first. So, please, do you know where is the problem?

Thanks for your help.

duff

Hi @duff,

PublishedArticleDAO::getPublishedArticles returns an array, not an iterator. To loop through its results, you’ll need to…

foreach ($articles as $article) {
    ...
}

…rather than using $articles->next().

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like