Exception with custom route

hi there, I have this custom route below but receive this exception. Somehow I didn’t get the message before. Any idea?

debug locally:
session_name(): Cannot change session name when headers already sent
/Users/agloeckner/Projects/web/myvita.digital/kirby/vendor/getkirby/toolkit/lib/s.php

// set the custom session name
session_name(static::$name);

debug on server:
session_start(): Cannot send session cache limiter - headers already sent (output started at /hermes/bosnaweb24a/b1075/ipg.alexandergloecknerco/myvita.digital/site/config/config.php:55)

/hermes/bosnaweb24a/b1075/ipg.alexandergloecknerco/myvita.digital/kirby/vendor/getkirby/toolkit/lib/s.php
// try to start the session
if(!session_start()) return false;

c::set('routes', array(
  array(
    'pattern' => '(:any)/cv-template-no-1',
    'action'  => function($uid) {
	  $page = page($uid);
      site()->visit('/' . $uid);

      tpl::$data = array_merge(tpl::$data, array(
        'kirby' => kirby(),
        'site'  => site(),
        'pages' => pages(),
        'page'  => page()
      ), $page->templateData());

      echo tpl::load(kirby()->roots()->templates() . DS . 'cv-template-no-1.php');
      return false;
    }
  )
));

Do you start a new session in that template?

Not intentionally, do I need to?

Oh no, I thought that might have caused the error message.

What is on line 55 in your config.php?

Is that a single language or multi-language site?

yes multi language and line 55 is the route.

<?php

/*

---------------------------------------
License Setup
---------------------------------------

Please add your license key, which you've received
via email after purchasing Kirby on http://getkirby.com/buy

It is not permitted to run a public website without a
valid license key. Please read the End User License Agreement
for more information: http://getkirby.com/license

*/

c::set('languages', array(
  array(
    'code'    => 'en',
    'name'    => 'EN',
    'default' => true,
    'locale'  => 'en_US',
    'url'     => '/',
  ),
    array(
    'code'    => 'de',
    'name'    => 'DE',
    'locale'  => 'de_DE',
    'url'     => '/de',
  ),
));

c::set('language.detect', true);

c::set('license', 'K2-PERSONAL-1f6080201f042643712274c4dfb70798');
c::set('cache', true);
c::set('debug', true);
c::set('panel.stylesheet', 'assets/css/panel.css');

c::set('routes', array(
  array(
    'pattern' => '(:any)/cv-template-no-1',
    'action'  => function($uid) {
	  $page = page($uid);
      site()->visit('/' . $uid);

      tpl::$data = array_merge(tpl::$data, array(
        'kirby' => kirby(),
        'site'  => site(),
        'pages' => pages(),
        'page'  => page()
      ), $page->templateData());

      echo tpl::load(kirby()->roots()->templates() . DS . 'cv-template-no-1.php');
      return false;
    }
  )
));


// c::set('panel.session.timeout', 10000);

s::$timeout = 60*24*30; // thirty days of session validity like in the Panel
s::$cookie['lifetime'] = 9999999; // don't let the cookie ever expire

// c::set('panel.session.timeout', 60*24*30);
// c::set('panel.session.lifetime', 60*24*30);

// GD Lib (default)
#c::set('thumbs.driver', 'gd');

// ImageMagick
c::set('thumbs.driver', 'im');

// plugin

// maps
c::set('map.key', 'AIzaSyCCQjEHFbkQk4tHdj_2fmbqWo2Z6v22fWg');

// focus
c::set('thumbs.driver', 'focus');

// c::set('panel.language', 'en');

c::set('plugin.logic.field', function($field, $page) {
  return snippet('logic-aboutv2.1', ['field' => $field, 'page' => $page], true);
});
//   return snippet('logic-' . $page->intendedTemplate(), ['field' => $field, 'page' => $page], true);


// Copy this code into your config.php file
// Replace the default $maxDimension to meet your needs
// Read more about Kirby's Panel hooks at https://getkirby.com/docs/panel/developers/hooks
// Shrink large images on upload

kirby()->hook('panel.file.upload', 'shrinkImage');
kirby()->hook('panel.file.replace', 'shrinkImage');
function shrinkImage($file, $maxDimension = 4000) {
  try {
    if ($file->type() == 'image' and ($file->width() > $maxDimension or $file->height() > $maxDimension)) {

      // Get original file path
      $originalPath = $file->dir().'/'.$file->filename();
      // Create a thumb and get its path
      $resized = $file->resize($maxDimension,$maxDimension);
      $resizedPath = $resized->dir().'/'.$resized->filename();
      // Replace the original file with the resized one
      copy($resizedPath, $originalPath);
      unlink($resizedPath);
    }
  } catch(Exception $e) {
    return response::error($e->getMessage());
  }
}
1 Like

Looks like it works if the language detect thingy is not present.

you’re right. But why?

Guess this happens because you echo the template. This should work:

return new Response(tpl::load(kirby()->roots()->templates() . DS . 'cv-template-no-1.php'), 'html', 200);
1 Like

That looks great. Thank you again! :blush: