# Exception with custom route

**URL:** <https://forum.getkirby.com/t/exception-with-custom-route/10080>\
**Category:** Questions\
**Tags:** v2\
**Created:** [March 26, 2018, 5:16pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080 "2018-03-26T17:16:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![agloeckner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/agloeckner/32/1573_2.png) [@agloeckner](https://forum.getkirby.com/u/agloeckner)\
**Post date:** [March 26, 2018, 5:16pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/1 "2018-03-26T17:16:57Z")

</div>

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;
    }
  )
));

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 26, 2018, 5:34pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/2 "2018-03-26T17:34:27Z")

</div>

Do you start a new session in that template?

---

<div class="post-metadata">

**Author:** ![agloeckner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/agloeckner/32/1573_2.png) [@agloeckner](https://forum.getkirby.com/u/agloeckner)\
**Post date:** [March 26, 2018, 5:38pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/3 "2018-03-26T17:38:50Z")

</div>

Not intentionally, do I need to?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 26, 2018, 5:43pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/4 "2018-03-26T17:43:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![agloeckner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/agloeckner/32/1573_2.png) [@agloeckner](https://forum.getkirby.com/u/agloeckner)\
**Post date:** [March 26, 2018, 5:53pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/5 "2018-03-26T17:53:33Z")

</div>

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());
  }
}
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 26, 2018, 6:02pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/6 "2018-03-26T18:02:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agloeckner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/agloeckner/32/1573_2.png) [@agloeckner](https://forum.getkirby.com/u/agloeckner)\
**Post date:** [March 26, 2018, 6:13pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/7 "2018-03-26T18:13:08Z")

</div>

you’re right. But why?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [March 26, 2018, 6:16pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/8 "2018-03-26T18:16:15Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![agloeckner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/agloeckner/32/1573_2.png) [@agloeckner](https://forum.getkirby.com/u/agloeckner)\
**Post date:** [March 26, 2018, 7:08pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/9 "2018-03-26T19:08:40Z")

</div>

That looks great. Thank you again! 😊

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:28pm UTC](https://forum.getkirby.com/t/exception-with-custom-route/10080/10 "2025-02-06T17:28:32Z")

</div>


