【问题标题】:Propel - fetchArray or toArray推进 - fetchArray 或 toArray
【发布时间】:2011-12-29 00:17:47
【问题描述】:

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

【问题讨论】:

    标签: php symfony1 doctrine symfony-1.4 propel


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以在->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());
      }
      

      【讨论】:

        【解决方案3】:

        您可以像使用数组一样迭代推进结果集

        $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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-08
          • 2014-01-18
          • 2017-04-10
          • 1970-01-01
          相关资源
          最近更新 更多