【发布时间】:2011-12-29 00:17:47
【问题描述】:
在 Doctrine 中,我可以使用函数 fetchArray() 而不是 execute 或 toArray()。我无法为 Propel 创建等效的这些功能。这可能吗?
【问题讨论】:
标签: php symfony1 doctrine symfony-1.4 propel
在 Doctrine 中,我可以使用函数 fetchArray() 而不是 execute 或 toArray()。我无法为 Propel 创建等效的这些功能。这可能吗?
【问题讨论】:
标签: php symfony1 doctrine symfony-1.4 propel
如果你真的需要数组,你总是可以使用旧的 Peer API
$criteria = new Criteria();
/* ...setup your criteria... */
$pdoStatement = AuthorPeer::doSelectStmt($criteria);
$array = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
【讨论】:
您可以在->find() 之后拨打toArray()。
一次:
$authors = AuthorQuery::create()
->limit(5)
->find()
->toArray();
foreach ($authors as $author) {
print_r($author);
}
或者在循环中:
$authors = AuthorQuery::create()
->limit(5)
->find()l
foreach ($authors as $author) {
print_r($author->toArray());
}
【讨论】:
您可以像使用数组一样迭代推进结果集
$authors = AuthorQuery::create()
->limit(5)
->find();
foreach ($authors as $author) {
echo $authors->getFirstName();
}
http://www.propelorm.org/documentation/03-basic-crud.html#collections_and_ondemand_hydration
【讨论】: