Propel - fetchArray或toArray

时间:2011-12-29 00:17:47

标签: php symfony1 doctrine symfony-1.4 propel

在Doctrine中我可以使用函数fetchArray()而不是execute或toArray()。我无法为Propel创建相同的这些功能。这可能吗?

3 个答案:

答案 0 :(得分:2)

如果你真的需要数组,你可以随时使用旧的Peer API

$criteria = new Criteria();
/* ...setup your criteria... */
$pdoStatement = AuthorPeer::doSelectStmt($criteria);
$array = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);

答案 1 :(得分:1)

您可以在toArray()之后致电->find()

立刻:

$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());
}

答案 2 :(得分:0)

您可以使用数组

迭代推进结果集
$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