douzhong3887 2018-07-24 09:31
浏览 81
已采纳

Magento - getEmail()在哪里定义?

You can find out the e-mail of the logged in user by using the following code:

$customer = Mage::getSingleton('customer/session')->getCustomer();
$mail = $customer->getEmail();

How to find out where getEmail() is defined?

I searched in app\code\core\Mage\Customer\Model\Resource\Customer.php but there is no function called getEmail().

I only found this:

_beforeSave method definition

So I tracked it back with NetBeans, and found the definition for Varien_Object in lib\Varien\Object.php.

But in there is no function getEmail() either.

I searched the whole project for the string public function getEmail(),

This is the result:

$ 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()
  • 写回答

1条回答 默认 最新

  • doulong2782 2018-07-29 11:43
    关注

    You wont find getEmail() definition because it doesn't exist.

    As you can see in the piece of code you are sharing, $customer is an instance of a Varien_Object. That class is defined in lib\Varien\Object.php.

    If you peek there, you'll see that the method isn't defined either... but that's because for better or worse Magento takes advantage of PHP's magic methods.

    When a non-existing method is called on this $customer instance, __call() is executed instead.

    This is the method definition for Varien_Object::_call():

    /**
     * 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).")");
    }
    

    From here on, the logic is pretty simple. Since $method will be getEmail, the first branch of the switch will be executed, and $key will be got from the method name (skipping the first three characters, since they must necessarily be "get", "set", "uns", or "has") and in this case it'll become "email".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c