【问题标题】:User tracking in CodeIgniterCodeIgniter 中的用户跟踪
【发布时间】:2012-06-16 11:54:16
【问题描述】:

我对 codeignitor 框架有点陌生。但我喜欢它的简单性。

我有一个应用程序要求系统需要记录所有用户活动。

例如:如果用户登录:那么我需要 <username> logged in <time> 之类的东西 如果他编辑他的个人资料:那么我需要<username> <edited> <time>

或类似的东西。

以便管理员可以查看所有活动...

有没有可用的库?或者我怎样才能以最完美的方式实现这一点?

请给我一些常用的方法..和意见。

谢谢。

【问题讨论】:

  • 这里有个常用的方法:写一个logger
  • @tereško 谢谢..很快就会记录你..

标签: php codeigniter frameworks


【解决方案1】:

为了获得最大的灵活性,编写您自己的日志函数。当我需要此功能时,我会在我使用的每个框架中包含以下功能/方法。 Wordpress/Codeigniter 等...

function log($msg = '', $level = 'INFO')
{
    $debug_backtrace = debug_backtrace();

    $time = date('c', time());
    $filename = PATH_TO_YOUR_SCRIPT . '/log/error_log.txt'; // file perms: 0646

    $output = "[$level] $time $msg\n";
    $output .= "{$debug_backtrace[0]['file']} : {$debug_backtrace[0]['line']}\n";

    if ( ! @file_put_contents($filename, $output, FILE_APPEND))
    {
        error_log("Failed to access log file [$filename] for writing: $msg");
    }
}

debug-backtrace允许获取调用日志函数的文件和行

【讨论】:

  • codeignitor 上有一个本地日志功能 ..我需要使用 DB ...这不是调试级别的跟踪器 ..我需要用户活动 ..
  • 我知道那些 CI 功能。我说For maximum flexibility...我使用这个记录器将任何类型的消息(调试/用户控制等)写入(易于阅读)文本文件。您可以根据需要编码$output,也可以使用global $wpdb;
  • 好的,同意。我需要的是使用 DB ..有什么办法吗?或可用的库而不是文本文件?
猜你喜欢
  • 1970-01-01
  • 2012-07-19
  • 2011-05-13
  • 2010-10-25
  • 2014-12-27
  • 2013-06-14
  • 1970-01-01
  • 2019-03-05
  • 1970-01-01
相关资源
最近更新 更多