0

getCollection() を使用して取得したものは、モデル、テーブル ノード、db への接続などだけです。しかし、データがここにあることはどこに示されていますか。そのため、ループする前に返されるデータがあることを知っておく必要があります。ありがとうございました!

object(Gagan_Faq_Model_Mysql4_Faq_Collection)[616]

 protected '_model' => string 'faq/faq' (length=7)
  protected '_resourceModel' => string 'faq/faq' (length=7)
  protected '_resource' => 
    object(Gagan_Faq_Model_Mysql4_Faq)[617]
      protected '_resources' => 
        object(Mage_Core_Model_Resource)[48]
          protected '_connectionTypes' => 
            array
              ...
          protected '_connections' => 
            array
              ...
          protected '_skippedConnections' => 
            array
              ...
          protected '_entities' => 
            array
              ...
          protected '_mappedTableNames' => null
      protected '_resourcePrefix' => string 'faq' (length=3)
      protected '_connections' => 
        array
          'write' => 
            object(Varien_Db_Adapter_Pdo_Mysql)[139]
              ...
          'read' => 
            object(Varien_Db_Adapter_Pdo_Mysql)[139]
              ...
      protected '_resourceModel' => string 'faq' (length=3)
      protected '_tables' => 
        array
          'dinkchika' => string 'gagan_faq' (length=9)
      protected '_mainTable' => string 'dinkchika' (length=9)
      protected '_idFieldName' => string 'faq_id' (length=6)
      protected '_isPkAutoIncrement' => boolean true
      protected '_useIsObjectNew' => boolean false
      protected '_fieldsForUpdate' => 
        array
          empty
      protected '_mainTableFields' => null
      protected '_uniqueFields' => null
      protected '_serializableFields' => 
        array
          empty
  protected '_fieldsToSelect' => null
  protected '_initialFieldsToSelect' => null
  protected '_fieldsToSelectChanged' => boolean false
  protected '_joinedTables' => 
    array
      empty
  protected '_mainTable' => string 'gagan_faq' (length=9)
  protected '_resetItemsDataChanged' => boolean false
  protected '_eventPrefix' => string '' (length=0)
  protected '_eventObject' => string '' (length=0)
  protected '_useAnalyticFunction' => boolean false
  protected '_conn' => 
    object(Varien_Db_Adapter_Pdo_Mysql)[139]
      protected '_defaultStmtClass' => string 'Varien_Db_Statement_Pdo_Mysql' (length=29)
      protected '_transactionLevel' => int 0
      protected '_connectionFlagsSet' => boolean true
      protected '_ddlCache' => 
        array
          1 => 
            array
              ...
          3 => 
            array
              ...
      protected '_bindParams' => 
        array
          empty
      protected '_bindIncrement' => int 0
      protected '_debug' => boolean false
      protected '_logQueryTime' => float 0.05
      protected '_logAllQueries' => boolean false
      protected '_logCallStack' => boolean false
      protected '_debugFile' => string 'var/debug/pdo_mysql.log' (length=23)
      protected '_debugIoAdapter' => null
      protected '_debugTimer' => int 0
      protected '_cacheAdapter' => 
        object(Varien_Cache_Core)[20]
          protected '_backend' => 
            object(Zend_Cache_Backend_File)[17]
              ...
          protected '_options' => 
            array
              ...
          protected '_specificOptions' => 
            array
              ...
          private '_lastId' (Zend_Cache_Core) => string 'bac_CONFIGURATION_FILES_ACCESS_LEVEL_VERIFICATION' (length=49)
          protected '_extendedBackend' => boolean true
          protected '_backendCapabilities' => 
            array
              ...
      protected '_isDdlCacheAllowed' => boolean true
      protected '_ddlColumnTypes' => 
        array
          'boolean' => string 'bool' (length=4)
          'smallint' => string 'smallint' (length=8)
          'integer' => string 'int' (length=3)
          'bigint' => string 'bigint' (length=6)
          'float' => string 'float' (length=5)
          'decimal' => string 'decimal' (length=7)
          'numeric' => string 'decimal' (length=7)
          'date' => string 'date' (length=4)
          'timestamp' => string 'timestamp' (length=9)
          'datetime' => string 'datetime' (length=8)
          'text' => string 'text' (length=4)
          'blob' => string 'blob' (length=4)
          'varbinary' => string 'blob' (length=4)
      protected '_ddlRoutines' => 
        array
          0 => string 'alt' (length=3)
          1 => string 'cre' (length=3)
          2 => string 'ren' (length=3)
          3 => string 'dro' (length=3)
          4 => string 'tru' (length=3)
      protected '_intervalUnits' => 
        array
          'YEARS' => string 'YEAR' (length=4)
          'MONTHS' => string 'MONTH' (length=5)
          'DAYS' => string 'DAY' (length=3)
          'HOURS' => string 'HOUR' (length=4)
          'MINUTES' => string 'MINUTE' (length=6)
          'SECOND' => string 'SECOND' (length=6)
      protected '_queryHook' => 
        array
          'object' => 
            object(Mage_Core_Model_Resource_Setup)[160]
              ...
          'method' => string 'callbackQueryHook' (length=17)
      protected '_pdoType' => string 'mysql' (length=5)
      protected '_numericDataTypes' => 
        array
          0 => int 0
          1 => int 1
          2 => int 2
          'INT' => int 0
          'INTEGER' => int 0
          'MEDIUMINT' => int 0
          'SMALLINT' => int 0
          'TINYINT' => int 0
          'BIGINT' => int 1
          'SERIAL' => int 1
          'DEC' => int 2
          'DECIMAL' => int 2
          'DOUBLE' => int 2
          'DOUBLE PRECISION' => int 2
          'FIXED' => int 2
          'FLOAT' => int 2
      protected '_config' => 
        array
          'host' => string 'localhost' (length=9)
          'username' => string 'root' (length=4)
          'password' => string '' (length=0)
          'dbname' => string 'm1' (length=2)
          'initStatements' => string 'SET NAMES utf8' (length=14)
          'model' => string 'mysql4' (length=6)
          'type' => string 'pdo_mysql' (length=9)
          'pdoType' => string '' (length=0)
          'active' => string '1' (length=1)
          'charset' => null
          'persistent' => boolean false
          'options' => 
            array
              ...
          'driver_options' => 
            array
              ...
      protected '_fetchMode' => int 2
      protected '_profiler' => 
        object(Zend_Db_Profiler)[73]
          protected '_queryProfiles' => 
            array
              ...
          protected '_enabled' => boolean false
          protected '_filterElapsedSecs' => null
          protected '_filterTypes' => null
      protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
      protected '_connection' => 
        object(PDO)[67]
      protected '_caseFolding' => int 0
      protected '_autoQuoteIdentifiers' => boolean true
      protected '_allowSerialization' => boolean true
      protected '_autoReconnectOnUnserialize' => boolean false
  protected '_select' => 
    object(Varien_Db_Select)[507]
      protected '_bind' => 
        array
          empty
      protected '_adapter' => 
        object(Varien_Db_Adapter_Pdo_Mysql)[139]
          protected '_defaultStmtClass' => string 'Varien_Db_Statement_Pdo_Mysql' (length=29)
          protected '_transactionLevel' => int 0
          protected '_connectionFlagsSet' => boolean true
          protected '_ddlCache' => 
            array
              ...
          protected '_bindParams' => 
            array
              ...
          protected '_bindIncrement' => int 0
          protected '_debug' => boolean false
          protected '_logQueryTime' => float 0.05
          protected '_logAllQueries' => boolean false
          protected '_logCallStack' => boolean false
          protected '_debugFile' => string 'var/debug/pdo_mysql.log' (length=23)
          protected '_debugIoAdapter' => null
          protected '_debugTimer' => int 0
          protected '_cacheAdapter' => 
            object(Varien_Cache_Core)[20]
              ...
          protected '_isDdlCacheAllowed' => boolean true
          protected '_ddlColumnTypes' => 
            array
              ...
          protected '_ddlRoutines' => 
            array
              ...
          protected '_intervalUnits' => 
            array
              ...
          protected '_queryHook' => 
            array
              ...
          protected '_pdoType' => string 'mysql' (length=5)
          protected '_numericDataTypes' => 
            array
              ...
          protected '_config' => 
            array
              ...
          protected '_fetchMode' => int 2
          protected '_profiler' => 
            object(Zend_Db_Profiler)[73]
              ...
          protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
          protected '_connection' => 
            object(PDO)[67]
              ...
          protected '_caseFolding' => int 0
          protected '_autoQuoteIdentifiers' => boolean true
          protected '_allowSerialization' => boolean true
          protected '_autoReconnectOnUnserialize' => boolean false
      protected '_parts' => 
        array
          'straightjoin' => boolean false
          'distinct' => boolean false
          'columns' => 
            array
              ...
          'union' => 
            array
              ...
          'from' => 
            array
              ...
          'where' => 
            array
              ...
          'group' => 
            array
              ...
          'having' => 
            array
              ...
          'order' => 
            array
              ...
          'limitcount' => null
          'limitoffset' => null
          'forupdate' => boolean false
      protected '_tableCols' => 
        array
          empty
  protected '_cacheConf' => null
  protected '_idFieldName' => null
  protected '_bindParams' => 
    array
      empty
  protected '_data' => null
  protected '_map' => null
  protected '_fetchStmt' => null
  protected '_isOrdersRendered' => boolean false
  protected '_items' => 
    array
      empty
  protected '_itemObjectClass' => string 'Gagan_Faq_Model_Faq' (length=19)
  protected '_orders' => 
    array
      empty
  protected '_filters' => 
    array
      empty
  protected '_isFiltersRendered' => boolean false
  protected '_curPage' => int 1
  protected '_pageSize' => boolean false
  protected '_totalRecords' => null
  protected '_isCollectionLoaded' => null
  protected '_cacheKey' => null
  protected '_cacheTags' => 
    array
      empty
  protected '_cacheLifetime' => int 86400
  protected '_flags' => 
    array
      empty
4

2 に答える 2

2
  1. Magento コレクションは、ループするまで、または を呼び出すまでロードloadされません。空のコレクションのループについて心配する必要はありません。何も返されない場合、PHP はエラーなしでループをスキップします。

  2. 読み込まれたコレクションには、入力された$_items配列があります

  3. コレクションモデルにはisLoadedメソッドがあり、ロードされているかどうかを確認できます

Re: 上記の 3 番目の項目

$products = Mage::getModel('some/model')->getCollection();
if($products->isLoaded())
{
    //,,,
}
else
{
    //,,,
}
于 2013-03-17T16:42:14.640 に答える
1

$collection = Mage::getResourceModel('catalog/product_collection');

$count = $collection->getSize(); 上記は、magento がコレクションを処理する標準的な方法です。製品について投稿しましたが、他のコレクションについても、異なるモデルを使用していますが、ほぼ同じ関数呼び出しを使用しています。

あなたのコードは不完全に見えます。

于 2013-03-17T19:15:16.757 に答える