首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento - getEmail()定义在哪里?

Magento - getEmail()定义在哪里?
EN

Stack Overflow用户
提问于 2018-07-24 17:31:03
回答 1查看 157关注 0票数 0

您可以使用以下代码来查找登录用户的电子邮件:

代码语言:javascript
复制
$customer = Mage::getSingleton('customer/session')->getCustomer();
$mail = $customer->getEmail();

如何找出定义getEmail()的位置?

我在app\code\core\Mage\Customer\Model\Resource\Customer.php中搜索,但没有名为getEmail()的函数。

我只找到了这个:

所以我用NetBeans回溯了一下,在lib\Varien\Object.php中找到了Varien_Object的定义。

但是在里面也没有getEmail()函数。

我在整个项目中搜索了字符串public function getEmail()

这就是结果:

代码语言:javascript
复制
$ grep -iR "public function getEmail()"
app/code/core/Mage/Catalog/Block/Product/Send.php:    public function getEmail()
app/code/core/Mage/Newsletter/Model/Subscriber.php:    public function getEmail()
app/code/core/Mage/Sendfriend/Block/Send.php:    public function getEmail()
app/code/core/_193_Mage/Catalog/Block/Product/Send.php:    public function getEmail()
app/code/core/_193_Mage/Newsletter/Model/Subscriber.php:    public function getEmail()
app/code/core/_193_Mage/Sendfriend/Block/Send.php:    public function getEmail()
app/code/_core/Mage/Catalog/Block/Product/Send.php:    public function getEmail()
app/code/_core/Mage/Newsletter/Model/Subscriber.php:    public function getEmail()
app/code/_core/Mage/Sendfriend/Block/Send.php:    public function getEmail()
lib/Payone/Api/Request/Parameter/Authorization/PersonalData.php:    public function getEmail()
lib/Payone/Api/Request/Parameter/CreateAccess/PersonalData.php:    public function getEmail()
lib/Payone/Api/Request/Parameter/ManageMandate/PersonalData.php:    public function getEmail()
lib/Payone/Api/Request/Parameter/Vauthorization/PersonalData.php:    public function getEmail()
lib/Zend/Gdata/App/Extension/Person.php:    public function getEmail()
lib/Zend/Gdata/Extension/Who.php:    public function getEmail()
lib/Zend/Service/ReCaptcha/MailHide.php:    public function getEmail()
lib/Zend/View/Helper/Gravatar.php:    public function getEmail()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-29 19:43:01

你找不到getEmail()定义,因为它不存在。

正如您在共享的代码片段中所看到的,$customerVarien_Object的一个实例。该类是在lib\Varien\Object.php中定义的。

如果你偷看那里,你会发现这个方法也没有定义……但这是因为Magento利用了PHP的magic methods

在此$customer实例上调用不存在的方法时,将改为执行__call()

这是Varien_Object::_call()的方法定义

代码语言:javascript
复制
/**
 * Set/Get attribute wrapper
 *
 * @param   string $method
 * @param   array $args
 * @return  mixed
 */
public function __call($method, $args)
{
    switch (substr($method, 0, 3)) {
        case 'get' :
            $key = $this->_underscore(substr($method,3));
            $data = $this->getData($key, isset($args[0]) ? $args[0] : null);
            return $data;
        case 'set' :
            $key = $this->_underscore(substr($method,3));
            $result = $this->setData($key, isset($args[0]) ? $args[0] : null);
            return $result;
        case 'uns' :
            $key = $this->_underscore(substr($method,3));
            $result = $this->unsetData($key);
            return $result;
        case 'has' :
            $key = $this->_underscore(substr($method,3));
            return isset($this->_data[$key]);
    }
    throw new Varien_Exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")");
}

从这里开始,逻辑非常简单。由于$method将为getEmail,因此将执行开关的第一个分支,并从方法名中获取$key (跳过前三个字符,因为它们必须是"get“、"set”、"uns“或"has"),在本例中将变为"email”。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51495187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档