2009-12-09 111 views
1

例如,我需要从此会话中检索一个值。我应该怎么做 ?确切地说,我需要获得“customer_log_id”。如何检索magento中的数组值

> Array (
>  [core] => Array 
>   (
>    [_session_validator_data] => Array 
>     (
>      [remote_addr] => 127.0.0.1 
>      [http_via] => 
>      [http_x_forwarded_for] => 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>    ) 
> 
>    [session_hosts] => Array 
>     (
>      [127.0.0.1] => 1 
>    ) 
> 
>    [messages] => Mage_Core_Model_Message_Collection 
> Object 
>     (
>      [_messages:protected] => Array 
>       (
>      ) 
> 
>      [_lastAddedMessage:protected] => 
>    ) 
> 
>    [visitor_data] => Array 
>     (
>      [] => 
>      [server_addr] => 2130706433 
>      [remote_addr] => 2130706433 
>      [http_secure] => 
>      [http_host] => 127.0.0.1 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>      [http_accept_language] => 
> en-us,en;q=0.5 
>      [http_accept_charset] => 
> ISO-8859-1,utf-8;q=0.7,*;q=0.7 
>      [request_uri] => /currentproject/magento/index.php/customer/account/ 
>      [session_id] => 34989ee1673caefec0d887dd41198587 
>      [http_referer] => http://127.0.0.1/currentproject/magento/index.php/customer/account/login/ 
>      [first_visit_at] => 2009-12-04 11:20:24 
>      [is_new_visitor] => 
>      [last_visit_at] => 2009-12-04 11:32:26 
>      [visitor_id] => 208 
>      [last_url_id] => 1399 
>      [catalog_compare_items_count] => 0 
>      [do_customer_login] => 
>      [customer_id] => 1 
>      [customer_log_id] => 8 
>    ) 
> 
>    [last_url] => http://127.0.0.1/currentproject/magento/index.php/customer/account/index/ 
>    [just_voted_poll] => 
>  ) 
> 
>  [_cookie_revalidate] => 1259926524 
>  [customer_base] => Array 
>   (
>    [_session_validator_data] => Array 
>     (
>      [remote_addr] => 127.0.0.1 
>      [http_via] => 
>      [http_x_forwarded_for] => 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>    ) 
> 
>    [session_hosts] => Array 
>     (
>      [127.0.0.1] => 1 
>    ) 
> 
>    [messages] => Mage_Core_Model_Message_Collection 
> Object 
>     (
>      [_messages:protected] => Array 
>       (
>      ) 
> 
>      [_lastAddedMessage:protected] => 
>    ) 
> 
>    [id] => 1 
>  ) 
> 
>  [checkout] => Array 
>   (
>    [_session_validator_data] => Array 
>     (
>      [remote_addr] => 127.0.0.1 
>      [http_via] => 
>      [http_x_forwarded_for] => 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>    ) 
> 
>    [session_hosts] => Array 
>     (
>      [127.0.0.1] => 1 
>    ) 
> 
>    [quote_id_1] => 
>  ) 
> 
>  [catalog] => Array 
>   (
>    [_session_validator_data] => Array 
>     (
>      [remote_addr] => 127.0.0.1 
>      [http_via] => 
>      [http_x_forwarded_for] => 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>    ) 
> 
>    [session_hosts] => Array 
>     (
>      [127.0.0.1] => 1 
>    ) 
> 
>    [messages] => Mage_Core_Model_Message_Collection 
> Object 
>     (
>      [_messages:protected] => Array 
>       (
>      ) 
> 
>      [_lastAddedMessage:protected] => 
>    ) 
> 
>  ) 
> 
>  [newsletter] => Array 
>   (
>    [_session_validator_data] => Array 
>     (
>      [remote_addr] => 127.0.0.1 
>      [http_via] => 
>      [http_x_forwarded_for] => 
>      [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 
>    ) 
> 
>    [session_hosts] => Array 
>     (
>      [127.0.0.1] => 1 
>    ) 
> 
>  ) 
> 
>) 
+0

我可以问你从哪里得到这个数组? – 2009-12-09 14:22:39

回答

1
$a['core']['visitor_data']['customer_log_id'] 
+0

非常感谢Lindqvist ...完美答案 – Fero 2009-12-10 12:48:18

1

看样子,你想检索来自$_SESSION阵列的信息。有两种方法可以做到这一点。作为另一个海报建议,你可以简单地砍出来的$_SESSION超全局正是如此的:

$logId = $_SESSION['core']['visitor_data']['customer_log_id']; 

然而,这是一个黑客位,以避免Magento的框架。 (从“正确性”的角度来看)更好的选择是使用Magento的会话管理。因此,我们有:

// we could also skip a step and just use Mage::getSingleton("core/session")->getVisitorData(), 
// but I wanted to add the datatypes for your reference 
$session = Mage::getSingleton("core/session"); // Mage_Core_Model_Session 
$customerData = $session->getVisitorData(); // array 
$logId = $customerData['customer_log_id']; // int 

希望帮助!

+1

感谢Mastey ... U只是告诉我另一种获取magento数组值的新方法。非常感谢您的回答。 – Fero 2009-12-12 04:11:06