有用的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/

目录
相关文章
|
编译器 定位技术 C++
【CMake高级技巧】如何创建一个通用的库查找模板?
【CMake高级技巧】如何创建一个通用的库查找模板?
39 0
|
3月前
|
人工智能 JavaScript 前端开发
让OpenAi给我写个JS的set对象的笔记和快速去重方法
让OpenAi给我写个JS的set对象的笔记和快速去重方法
21 0
|
4月前
|
存储 Go
Go 语言之 Maps 详解:创建、遍历、操作和注意事项
Maps用于以键值对的形式存储数据值。Maps中的每个元素都是一个键值对。Maps是一个无序且可更改的集合,不允许重复。Maps的长度是其元素的数量。您可以使用 len() 函数来查找长度。Maps的默认值是 nil。Maps保存对底层哈希表的引用。
40 0
|
11月前
|
编译器 C语言 C++
软件开发入门教程网 Search之C++ 类 & 对象
C++ 在 C 语言的基础上增加了面向对象编程,C++ 支持面向对象程序设计。类是 C++ 的核心特性,通常被称为用户定义的类型。
|
11月前
|
算法 索引
实用工具类---给List数据加索引
实用工具类---给List数据加索引
DHL
|
算法 前端开发 安全
Kotlin StateFlow 搜索功能的实践 DB + NetWork
这篇文章主要来分析一下 PokemonGo 搜索功能的实践
DHL
428 0
Kotlin StateFlow 搜索功能的实践 DB + NetWork
如何使用代码获得ABAP repository object不同版本的内容
Created by Jerry Wang, last modified on Dec 21, 2014
86 0

热门文章

最新文章