Feed Addon - need help with setting mime type - error in Lime - solved

I wrote an addon to provide rss feeds as api endpoints. It works fine, if I call it through the API.

Before returning the output, I change the document mime type to rss:

If I call it with Lime, I get a
Warning: Creating default object from empty value in E:\github\cockpit\addons\Feed\bootstrap.php on line 23.

My folder structure is the following:


content of feed.php

// error_reporting(0); // hide warning at top of xml feed

//include cockpit

$app = new Lime\App();

$app->bind("/", function() use($app) {
    // $app->response->mime = 'rss'; // set mime type manually
    return cockpit('feed')->feed('pages');


Has someone a hint, how to set the mime type in a better way?

there is no response object, because you use cockpit as a libary here. $this->app->response->mime = 'rss'; should only be used in route bindings ($app->bind("/", ...))

OK. I don’t understand 100% why it doesn’t work, but I fixed my issue now with

if (COCKPIT_API_REQUEST) $this->app->response->mime = 'rss';

And it’s OK for me to add the mime type manually if I use it in a library. Thanks for pointing me in that direction.

This is the right way:

$app->bind("/", function() { 
   $this->response->mime = 'rss'; // set mime type manually 
   return cockpit('feed')->feed('pages'); 

module api functions e.g. cockpit('feed')->feed should never set/send any headers.

add $this->app->response->mime = 'rss'; here:

Ah, OK. Now I get it. Notice to myself: “Never mix up internal data and outputs again!”

I fixed it with my last commit. Thanks.