哪一行告诉集合有从数据库表中捕获的一些数据?

时间:2013-03-17 14:56:38

标签: magento

这是我使用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

2 个答案:

答案 0 :(得分:2)

  1. Magento集合不会加载,直到循环播放,或直到您致电load。您不必担心循环空集合。如果没有返回任何内容,PHP将跳过循​​环而不会出现错误

  2. 已加载的集合将具有已填充的$_items数组

  3. 收藏模型有一个isLoaded方法,可让您检查它们是否已加载

  4. Re:上面的第三项

    $products = Mage::getModel('some/model')->getCollection();
    if($products->isLoaded())
    {
        //,,,
    }
    else
    {
        //,,,
    }
    

答案 1 :(得分:1)

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

$ count = $ collection-> getSize(); 以上是标准方式magento处理集合。 我已发布了产品,但对于其他系列,它也使用了不同的模型,但功能调用几乎相同。

您的代码看起来不完整。