magento visitor logs

江枫思渺然 提交于 2019-12-24 01:28:10

问题


Is there a way to access the user logs in Magento? I know the database has a table called log_visitor that can see logs visitors, and log_visitor_info logs more info about the visitors (IP, user agent). How do I get to that data? When I write

$visitors = Mage::getModel('log/visitor')->getCollection()
foreach ($visitors as $visitor)  {
    print_r($visitor->getData());
}

I get an error PHP Fatal error: Uncaught exception 'Exception' with message 'Recoverable Error: Method Varien_Db_Select::__toString() must return a string value in /path/to/server/lib/Varien/Db/Adapter/Pdo/Mysql.php on line 272' in /path/to/server/app/code/core/Mage/Core/functions.php:239


回答1:


You can use the direct database query if you're not sure about object's API.

For example

      $read = Mage::getSingleton('core/resource')->getConnection('core_read');

      $results = $read->fetchAll("select * from log_visitor_info");

      foreach($resulst as $res)
        echo $res['http_referer'] . " - " . $res['http_user_agent'] . " - " . $res['remote_addr'] . " - ";



回答2:


You need to use var_dump or var_export on php objects.

The following code will output each visitor object:

$visitors = Mage::getModel('log/visitor')->getCollection();

foreach ($visitors as $visitor) {
        var_dump($visitor);
}


来源:https://stackoverflow.com/questions/7147564/magento-visitor-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!