# Accessing $kirby inside route

**URL:** <https://forum.getkirby.com/t/accessing-kirby-inside-route/12402>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 23, 2019, 10:22pm UTC](https://forum.getkirby.com/t/accessing-kirby-inside-route/12402 "2019-01-23T22:22:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![afincato](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/afincato/32/3446_2.png) [@afincato](https://forum.getkirby.com/u/afincato)\
**Post date:** [January 23, 2019, 10:22pm UTC](https://forum.getkirby.com/t/accessing-kirby-inside-route/12402/1 "2019-01-23T22:22:48Z")

</div>

i need to send an automatic email response after a user signs up through a form.

once i get the data in the route plugin through POST from the frontend, i was thinking it was possible to

```auto
try {
  $kirby->email([
    'from' => 'welcome@supercompany.com',
    'to' => 'someone@gmail.com',
    'subject' => 'Welcome!',
    'body'=> 'It\'s great to have you with us',
  ]);
} catch (Exception $error) {
  echo $error;
}

```

but `$kirby` is not accessible. i tried to set a callback to the route plugin like so

```auto
Kirby::plugin('your/plugin', [
  'routes' => function ($kirby) {
      return [
          [
              'pattern' => 'something',
              'action' => function () {

                try {
                  $kirby->email([
                    'from' => 'welcome@supercompany.com',
                    'to' => 'someone@gmail.com',
                    'subject' => 'Welcome!',
                    'body'=> 'It\'s great to have you with us',
                  ]);
               } catch (Exception $error) {
                 echo $error;
               }

            }
         ]
    ];
  }
]);

```

but not working as well. then i tried to set up a `route:after` hook, and the hook works once the route above gets visited, but i don’t know how to pass the data to it?

(i thought of making a GET call to the route where i send the form data, but i don’t think you can nest hooks within hooks right?)

i guess i can setup a controller to make the GET call and use the form data to send the email, as i imagine in the controller i can use the `$kirby` object.

but is there any better and simpler approach to this?

---

<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:** [January 23, 2019, 10:35pm UTC](https://forum.getkirby.com/t/accessing-kirby-inside-route/12402/2 "2019-01-23T22:35:48Z")

</div>

You should be able the Kirby object from anywhere using the `kirby()` helper:

```auto
$kirby = kirby();

```

Please choose your topic categories wisely…😉 And in any case a category that fits your Kirby version. Thanks.

---

<div class="post-metadata">

**Author:** ![afincato](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/afincato/32/3446_2.png) [@afincato](https://forum.getkirby.com/u/afincato)\
**Post date:** [January 23, 2019, 10:45pm UTC](https://forum.getkirby.com/t/accessing-kirby-inside-route/12402/3 "2019-01-23T22:45:46Z")

</div>

thanks! working…

i tried that also before, but instead of bounding `kirby()` to a variable, i used it directly in the function and it did not do much.

and yes, i opened this topic at the end of a long day, i’ll make sure to add those categories from now on! 😄
