RESOLVED: setUserPreference :'No entry is registered for key 'config'



I am trying to save a custom user preference through the API.

This is my code:

function save_http()
   global $_HTTP;
   //$_HTTP is an array like $_REQUEST

   //Export to string for storage
   $_HTTP = var_export($_HTTP, true);
   $request = new Piwik_API_Request
   $result = $request->process();

I keep getting this back:

Fatal error: Uncaught exception ‘Zend_Exception’ with message ‘No entry is registered for key ‘config’’ in D:\UniServer\www\dashboard\piwik\libs\Zend\Registry.php:147
Stack trace:
#0 D:\UniServer\www\dashboard\piwik\core\Piwik.php(160): Zend_Registry::get(‘config’)
#1 D:\UniServer\www\dashboard\piwik\core\Piwik.php(197): Piwik::isHttps()
#2 D:\UniServer\www\dashboard\piwik\core\DataTable\Renderer\Json.php(78): Piwik::overrideCacheControlHeaders()
#3 D:\UniServer\www\dashboard\piwik\core\DataTable\Renderer\Json.php(30): Piwik_DataTable_Renderer_Json::renderHeader()
#4 D:\UniServer\www\dashboard\piwik\core\API\ResponseBuilder.php(130): Piwik_DataTable_Renderer_Json->renderException()
#5 D:\UniServer\www\dashboard\piwik\core\API\Request.php(125): Piwik_API_ResponseBuilder->getResponseException(Object(Zend_Exception))
#6 D:\UniServer\www\dashboard\utils.php(239): Piwik_API_Request->process()
#7 D:\UniServer\www\dashboard\index.php(321): save_http()
#8 {main}
thrown in D:\UniServer\www\dashboard\piwik\libs\Zend\Registry.php on line 147

Any ideas?
I can use the setUserPreference for other things such as defaultReport but it appears it doesn’t like me using a custom preference?

(vipsoft) #2

See the example in misc/api_internal_call.php. You should include “index.php” or copy the code so that FrontController init() is called. This is where a lot of initialization is done (e.g., loading the config files).



I am using the API, those files are included outside of the function but the API request is made inside it (I’ve done this in other places too and it has worked perfectly).

I’m stumped!


Resolved - I forgot to use this in the function: