推动多次返回相同的记录

Propel returning same record multiple times

我有一个非常简单的数据库 (MySql),其中有一个 table,我正在使用带有此代码的 Propel 访问它...

<?php
$autoloader = require '/vendor/autoload.php';
$autoloader->add('', __DIR__ . '/generated-classes/');

use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;

require './generated-conf/config.php';
require './includes/pagebuilder.php';

Propel::getConnection("default")->useDebug(true);

$videos = VideosQuery::create()
    ->orderByAddeddate()
    ->paginate($page = 1, $maxPerPage = 20);

echo GetMainPage($videos);
echo Propel::getConnection()->getLastExecutedQuery();
?>

查询似乎生成正确...

SELECT videos.id, videos.AddedDate, videos.Rating, videos.Views, videos.Title, videos.Description, videos.ImageUrl, videos.EmbedUrl FROM videos ORDER BY videos.AddedDate ASC LIMIT 20

如果我 运行 通过 phpMyAdmin 这个查询我得到了预期的结果,但是,Propel 似乎返回了 20 次查询找到的第一条记录。有人知道这里会发生什么吗? 谢谢

编辑:录制循环

function GetMainContent($videos) {
    $mc = '<main>
            <div id="video-box-wrapper">';

    foreach($videos as $video) {
        $mc .= '<div class="video-box">
                    <a href="#">
                        <img src="' . $video->getImageUrl() . '" />
                        <span>' . $video->getTitle() . '</span>
                        <br />
                        <p>' . $video->getViews() . ' views</p>
                        <p>Rating: ' . $video->getRating() . '/10</p>
                    </a>
                </div>';
    }
    $mc .= '</main>';

    return $mc;
}

我使用 propel 的 init 命令从现有数据库生成的模式是在为该 table 设置主键之前创建的。这导致 Propel 在一个查询中多次 return 相同的记录。 这已通过使用适当的主键重新生成架构来解决。