Call Piwik API in PHP approach with CodeIgniter causes blank/white screen

Everything went fine when I tried out ‘calling the API in PHP’ approach documented at the link below without CodeIgniter.

http://piwik.org/docs/analytics-api/calling-techniques/#toc-call-the-piwik-api-in-php

I was able to get results… however, when I tried the approach Using the CodeIgniter framework, I get a blank screen when I call

Piwik_FrontController::getInstance()->init();

I took a look at my error log and I noticed that I start to get the following error when I try the approach with CodeIgniter:

[14-Aug-2011 04:17:11] PHP Fatal error: Class ‘Controller’ not found in /home/test/application/controllers/products.php on line 3

Controller exist since it works fine when I take out Piwik API from CodeIgniter…

anyone else having the same problem? i tried to check if exit or die is being called but i dont think that’s the issue… im guessing that the

Piwik_FrontController::getInstance()->init();

call is causing the issue somehow… any thoughts would be greatly appreciated!

I would actually use the PHP Tracker API : Tracking API - Analytics Platform - Matomo

Hi JulienM–what I’m trying to achieve is actually to use the API to obtain the analytics…

My mistake, in that case I would use http://piwik.org/docs/analytics-api/calling-techniques/#toc-call-the-piwik-api-using-the-rest-api-over-http to avoid any conflict with your framework and Piwik internals.

I’ve used that approach and it works fine–however, the reason why I’m trying to call the API using the second approach is for better response time. I have Piwik installed on the same server and it doesn’t make sense for me to call the API over http… when I do, the response time is dramatically affected

Piwik doesn’t have a ‘Controller’ class. I’m guessing this is from CodeIgniter. In which case, check your include path, autoloader, and/or current working directory (in case, CodeIgniter uses relative include paths).

hi anthon–i did that–it works fine if I dont use the approach below–but when I do, codeigniter and piwik doesn’t seem to interact very well causing the error… =/

<?php // if you don't include 'index.php', you must also define PIWIK_DOCUMENT_ROOT // and include "libs/upgradephp/upgrade.php" and "core/Loader.php" define('PIWIK_INCLUDE_PATH', realpath('..')); define('PIWIK_USER_PATH', realpath('..')); define('PIWIK_ENABLE_DISPATCH', false); define('PIWIK_ENABLE_ERROR_HANDLER', false); define('PIWIK_ENABLE_SESSION_START', false); require_once PIWIK_INCLUDE_PATH . "/index.php"; require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php"; Piwik_FrontController::getInstance()->init(); // This inits the API Request with the specified parameters $request = new Piwik_API_Request(' method=UserSettings.getResolution &idSite=7 &date=yesterday &period=week &format=XML &filter_limit=3 &token_auth=anonymous '); // Calls the API and fetch XML data back $result = $request->process(); echo $result;

The error message isn’t from Piwik. Have you tried looking at the backtrace?

I am having the same issue. I am using Codeigniter. I have created installed Piwik outside the application folder. I can’t figure it out the API. Please share your knowledge if you have solved this issue.