newsModel = new NewsModel(); $this->userModel = new UserModel(); $this->auditLogModel = new AuditLogModel(); } public function index() { // Get news statistics $totalNews = $this->newsModel->countByStatus(); $publishedNews = $this->newsModel->countByStatus('published'); $draftNews = $this->newsModel->countByStatus('draft'); // Get pages statistics (query directly since no PageModel) $db = \Config\Database::connect(); $totalPages = $db->table('pages')->countAllResults(); $publishedPages = $db->table('pages')->where('status', 'published')->countAllResults(); $draftPages = $db->table('pages')->where('status', 'draft')->countAllResults(); // Get users statistics $totalUsers = $this->userModel->countAllResults(); $activeUsers = $this->userModel->where('is_active', 1)->countAllResults(); // Get recent audit logs (limit 10) $recentAuditLogs = $this->auditLogModel->select('audit_logs.*, users.username') ->join('users', 'users.id = audit_logs.user_id', 'left') ->orderBy('audit_logs.created_at', 'DESC') ->limit(10) ->findAll(); $data = [ 'title' => 'Dashboard', 'stats' => [ 'news' => [ 'total' => $totalNews, 'published' => $publishedNews, 'draft' => $draftNews, ], 'pages' => [ 'total' => $totalPages, 'published' => $publishedPages, 'draft' => $draftPages, ], 'users' => [ 'total' => $totalUsers, 'active' => $activeUsers, ], ], 'recentAuditLogs' => $recentAuditLogs, ]; return view('admin/dashboard', $data); } }