检查属性是客户属性还是客户地址属性

时间:2011-12-16 15:21:37

标签: php zend-framework magento

我有以下代码,我需要检查有问题的属性是客户属性还是客户地址属性。我该如何检查?

private $custom_columns = array();

public function __construct() 
{
    parent::__construct();
    $this->setId('customerGrid');
    $this->setUseAjax(true);
    $this->setDefaultSort('email');
    $this->setDefaultLimit('200');
    $this->setSaveParametersInSession(true);
    $attributeIds = Mage::getStoreConfig('sectionname/group/field');
    $this->custom_columns = array($attributeIds); 
}

$attributeIds return attribute codes like street if I select Street Address, gender if I select Gender and so on. Now what condition should be put in order to know whether a given attribute is customer or address attribute.

public function __construct() 
{
    parent::__construct();
    $this->setId('customerGrid');
    $this->setUseAjax(true);
    $this->setDefaultSort('email');
    $this->setDefaultLimit('200');
    $this->setSaveParametersInSession(true);
    $attributeIds = Mage::getStoreConfig('sectionname/group/field');
    $this->custom_columns = array($attributeIds); 
}

我只是想知道那些条件会是什么。希望这更清楚一点

1 个答案:

答案 0 :(得分:0)

您可以对每个扩展has*()的类使用magic Varien_Object次调用来检查某个属性是否存在。

此外,Varien_Object提供了非魔法hasData('property_name')方法。

hasData()方法基本上只是间接地做同样的事情 - 即通过将属性名称作为参数传递给方法,而不是将其用作方法名称的驼峰式部分。

Mage_Customer_Model_CustomerMage_Customer_Model_Address实际上扩展了Varien_Object,因此您可以在对象实例上调用hasData('street')来检查是否存在此类属性,并将结果用于您的if/else场景。

您还可以神奇地调用hasStreet(),但在您的情况下,hasData()变体肯定会更好(因为您通过具有可变属性名称的数组循环)。

请注意,hasData()只能帮助您区分唯一属性名称。当然,您不能使用hasData()来区分两个类中存在的同名属性(例如'entity_id')。