本文整理汇总了PHP中Varien_Data_Collection::getFirstItem方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Collection::getFirstItem方法的具体用法?PHP Varien_Data_Collection::getFirstItem怎么用?PHP Varien_Data_Collection::getFirstItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Collection
的用法示例。
在下文中一共展示了Varien_Data_Collection::getFirstItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFirstItem
/**
* Get the first item in the collection. As the inherited behavior of creating
* a new empty item when the collection is empty cannot be achieved here,
* (@see self::getNewEmptyItem) this method will throw an exception if called
* on an empty collection.
* @return EbayEnterprise_Catalog_Model_Pim_Product
* @throws EbayEnterprise_Catalog_Model_Pim_Product_Collection_Exception If collection is empty
*/
public function getFirstItem()
{
if (empty($this->_items)) {
throw new EbayEnterprise_Catalog_Model_Pim_Product_Collection_Exception(sprintf('%s cannot get item from an empty collection', __METHOD__));
}
return parent::getFirstItem();
}
示例2: collectionsAction
public function collectionsAction()
{
$thing_1 = new Varien_Object();
$thing_1->setName('david');
$thing_1->setAge('27');
$thing_1->setLastName('Smith');
$thing_2 = new Varien_Object();
$thing_2->setName('Jane');
$thing_2->setAge(12);
$thing_3 = new Varien_Object();
$thing_3->setName('Spot');
$thing_3->setLastName('The Dog');
$thing_3->setAge(7);
//var_dump($thing_3->getData());
//var_dump($thing_3["last_name"]);
/*Definiremos ahora una serie de collections*/
$collection_of_things = new Varien_Data_Collection();
$collection_of_things->addItem($thing_1)->addItem($thing_2)->addItem($thing_3);
foreach ($collection_of_things as $thing) {
var_dump($thing->getData());
}
echo "<br><br>";
echo "obteniendo el primer y último elemento";
echo "<br><br>";
var_dump($collection_of_things->getFirstItem());
var_dump($collection_of_things->getLastItem()->getData());
echo "<br><br>";
echo "Ahora como xml";
var_dump($collection_of_things->toXml());
echo '<br><br>';
echo 'ahora obtenemos solo las columnas identificadas como name';
echo '<br><br>';
var_dump($collection_of_things->getColumnValues('name'));
echo '<br><br>';
echo 'El equipo de Magento nos permite realizar filtrados, ejemplo para el nombre david';
echo '<br/><br>';
var_dump($collection_of_things->getItemsByColumnValue('name', 'Spot'));
}