如何在PHP中调试受保护区域?

时间:2015-08-12 18:12:27

标签: php magento

目前我正在使用Magento 1.9。 C.F. SOMagento.SE

我正在检查Magento如何处理发布的数据,因为发布的数据有一个非空的姓氏,而客户模型似乎是空的。

我遇到问题的代码如下:

public function createPostAction()
{
    /** @var $session Mage_Customer_Model_Session */
    $session = $this->_getSession();
    if ($session->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session->setEscapeMessages(true); // prevent XSS injection in user input
    if (!$this->getRequest()->isPost()) {
        $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
        $this->_redirectError($errUrl);
        return;
    }

    $customer = $this->_getCustomer();

    try {
        $errors = $this->_getCustomerErrors($customer);

        if (empty($errors)) {
            $customer->cleanPasswordsValidationData();
            $customer->save();
            $this->_dispatchRegisterSuccess($customer);
            $this->_successProcessRegistration($customer);
            return;
        } else {
            $this->_addSessionError($errors);
        }
    } catch (Mage_Core_Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost());
        if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
            $url = $this->_getUrl('customer/account/forgotpassword');
            $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
            $session->setEscapeMessages(false);
        } else {
            $message = $e->getMessage();
        }
        $session->addError($message);
    } catch (Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost())
            ->addException($e, $this->__('Cannot save the customer.'));
    }
    $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
    $this->_redirectError($errUrl);
}

我几乎可以肯定$customer = $this->_getCustomer();发生了一些不好的事情,但当我var_dump($customer)时,大多数地区都受到保护。

object(Mage_Customer_Model_Customer)#84 (21) {
  ["_eventPrefix":protected]=>
  string(8) "customer"
  ["_eventObject":protected]=>
  string(8) "customer"
  ["_errors":protected]=>
  array(0) {
  }
  ["_attributes":protected]=>
  NULL
  ["_addresses":protected]=>
  NULL
  ["_addressesCollection":protected]=>
  NULL
  ["_isDeleteable":protected]=>
  bool(true)
  ["_isReadonly":protected]=>
  bool(false)
  ["_cacheTag":protected]=>
  string(8) "customer"
  ["_resourceName":protected]=>
  string(17) "customer/customer"
  ["_resource":protected]=>
  NULL
  ["_resourceCollectionName":protected]=>
  string(28) "customer/customer_collection"
  ["_dataSaveAllowed":protected]=>
  bool(true)
  ["_isObjectNew":protected]=>
  NULL
  ["_data":protected]=>
  array(2) {
    ["entity_id"]=>
    NULL
    ["group_id"]=>
    string(1) "1"
  }
  ["_hasDataChanges":protected]=>
  bool(true)
  ["_origData":protected]=>
  NULL
  ["_idFieldName":protected]=>
  string(9) "entity_id"
  ["_isDeleted":protected]=>
  bool(false)
  ["_oldFieldsMap":protected]=>
  array(0) {
  }
  ["_syncFieldsMap":protected]=>
  array(0) {
  }
}

有什么办法可以看透吗?如果没有,我该怎么办呢?

1 个答案:

答案 0 :(得分:1)

您需要确保 Mage_Customer_Model_Customer 的方法 getAddresses ,如下所示

public function getAddresses()
{
     return $this->_addresses;
}