有用的Magento Collection函数

简介:

There are different important functions that you can implement in your Collection object. The functions are present in Varien_Data_Collection_Db class. The class file is present in lib/Varien/Data/Collection/Db.php

Here are some of the functions that you can use in your collection object:-

/**
* Get Zend_Db_Select instance
*/
$collection->getSelect();

/**
* Get collection size
*/
$collection->getSelect()->getSize();

/**
* Get sql select string or object
*/
$collection->getSelect()->getSelectSql();

/**
* Add select order
*/
$collection->getSelect()->setOrder($field, $direction);

/**
* Add field filter to collection
*
* If $attribute is an array will add OR condition with following format:
* array(
*     array(‘attribute’=>’firstname’, ‘like’=>’test%’),
*     array(‘attribute’=>’lastname’, ‘like’=>’test%’),
* )
*/
$collection->getSelect()->setOrder($field, $condition);

/**
* Set select distinct
*/
$collection->getSelect()->distinct($flag);

/**
* Get all data array for collection
*/
$collection->getSelect()->getData();

/**
* Reset loaded for collection data array
*/
$collection->getSelect()->resetData();

/**
* Print and/or log query
*/
$collection->getSelect()->printLogQuery(true, true);

More functions below:-

Varien_Data_Collection_Db class extends Varien_Data_Collection class. Here are some more functions present in Varien_Data_Collection class:-/**
* Get current collection page
*/
$collection->getSelect()->getCurPage();

/**
* Retrieve collection last page number
*/
$collection->getSelect()->getLastPageNumber();

/**
* Retrieve collection page size
*/
$collection->getSelect()->getPageSize();

/**
* Retrieve collection all items count
*/
$collection->getSelect()->getSize();

/**
* Retrieve collection first item
*/
$collection->getSelect()->getFirstItem();

/**
* Retrieve collection last item
*/
$collection->getSelect()->getLastItem();

/**
* Retrieve collection items
*/
$collection->getSelect()->getItems();

/**
* Clear collection
*/
$collection->getSelect()->clear();

You can also use the select functions as present in Zend_Db_Select class. This class file is present in lib/Zend/Db/Select.php

Hope this helps. Thanks.

 

来自:http://blog.chapagain.com.np/magento-collection-functions/

目录
相关文章
|
存储 SQL Oracle
Oracle存储过程中如何使用数组(附范例)
Oracle存储过程中如何使用数组(附范例)
|
6月前
|
网络协议 Serverless Python
函数计算操作报错合集之安装ebsynth_utility插件时报错,该如何处理
在使用函数计算服务(如阿里云函数计算)时,用户可能会遇到多种错误场景。以下是一些常见的操作报错及其可能的原因和解决方法,包括但不限于:1. 函数部署失败、2. 函数执行超时、3. 资源不足错误、4. 权限与访问错误、5. 依赖问题、6. 网络配置错误、7. 触发器配置错误、8. 日志与监控问题。
215 1
|
5月前
【Azure Developer】使用PowerShell Where-Object方法过滤多维ArrayList时候,遇见的诡异问题 -- 当查找结果只有一个对象时,返回结果修改了对象结构,把多维变为一维
【Azure Developer】使用PowerShell Where-Object方法过滤多维ArrayList时候,遇见的诡异问题 -- 当查找结果只有一个对象时,返回结果修改了对象结构,把多维变为一维
|
7月前
|
存储 安全 Java
提升编程效率的利器: 解析Google Guava库之集合篇Table二维映射(四)
提升编程效率的利器: 解析Google Guava库之集合篇Table二维映射(四)
|
8月前
|
存储 Go
Go 语言之 Maps 详解:创建、遍历、操作和注意事项
Maps用于以键值对的形式存储数据值。Maps中的每个元素都是一个键值对。Maps是一个无序且可更改的集合,不允许重复。Maps的长度是其元素的数量。您可以使用 len() 函数来查找长度。Maps的默认值是 nil。Maps保存对底层哈希表的引用。
94 0
|
编译器 C语言 C++
软件开发入门教程网 Search之C++ 类 & 对象
C++ 在 C 语言的基础上增加了面向对象编程,C++ 支持面向对象程序设计。类是 C++ 的核心特性,通常被称为用户定义的类型。
|
Python
python初学者指南:列表,元祖,字典,集合的使用场景对比及操作异同点分析
python初学者指南:列表,元祖,字典,集合的使用场景对比及操作异同点分析
245 0
python初学者指南:列表,元祖,字典,集合的使用场景对比及操作异同点分析
|
JSON Go 数据格式
Go 开发常用操作技巧--map
map 是一种特殊的数据类型,它是一种元素对的无序集合,元素对为 键(key)值(value) 形式。我们可以通过 key 来快速找到与之对应的 value。
146 0
Go 开发常用操作技巧--map