本文整理汇总了PHP中Varien_Data_Collection::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Collection::toArray方法的具体用法?PHP Varien_Data_Collection::toArray怎么用?PHP Varien_Data_Collection::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Collection
的用法示例。
在下文中一共展示了Varien_Data_Collection::toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listing
/**
* List all Cache types
*
* @return MageHack_MageConsole_Model_Abstract
*/
public function listing()
{
$collection = new Varien_Data_Collection();
foreach (Mage::app()->getCacheInstance()->getTypes() as $type) {
$collection->addItem($type);
}
if (!$collection->count()) {
$message = 'This is strange, we did not find any cache types.';
$this->setType(self::RESPONSE_TYPE_MESSAGE);
$this->setMessage($message);
} else {
if ($collection->count() > 0) {
$values = $collection->toArray();
if (is_array($values) && $values['totalRecords'] > 0) {
foreach ($values['items'] as $row) {
if (is_array($row)) {
$_values[] = array_intersect_key($row, $this->_attrToShow);
}
}
if (Mage::getStoreConfig('admin/mageconsole/html_tables') != 1) {
$this->setType(self::RESPONSE_TYPE_MESSAGE);
$message = Mage::helper('mageconsole')->createTable($_values, true, $this->_columnWidths);
$this->setMessage($message);
} else {
$this->setMessage($_values);
$this->setType(self::RESPONSE_TYPE_LIST);
}
}
}
}
return $this;
}
示例2: getCsv
public function getCsv(Varien_Data_Collection $collection, $getAll = false)
{
$csv = '';
$collectionData = $collection->toArray();
$type = $collection->getEntity()->getType();
// first pass, collect header
$_columns = array();
$_ignoredColumns = array();
// speedup
foreach ($collectionData as $item) {
foreach ($item as $key => $value) {
if (gettype($value) == 'Array') {
$_ignoredColumns[] = $key;
}
if ($getAll) {
$_columns[] = $key;
} else {
if (!in_array($key, $_columns) && !in_array($key, $_ignoredColumns)) {
$attr = Mage::getModel('eav/entity_attribute')->loadByCode($type, $key);
// get rid of non-attributes
if (!count($attr->getData())) {
$_ignoredColumns[] = $key;
} else {
$_columns[] = $key;
}
}
}
}
}
$data = array();
// add headers as first row
foreach ($_columns as $column) {
$data[] = "\"{$column}\"";
}
$csv .= implode(',', $data) . "\n";
// second pass, concatenate data content
foreach ($collectionData as $item) {
$data = array();
foreach ($_columns as $column) {
$data[] = '"' . str_replace(array('"', '\\'), array('""', '\\\\'), $item[$column]) . '"';
}
$csv .= implode(',', $data) . "\n";
}
return $csv;
}
示例3: _getCollectionData
/**
*
* @param Varien_Data_Collection $collection
* @return array
*/
protected function _getCollectionData(Varien_Data_Collection $collection)
{
return array_values($collection->toArray());
}