# Using the Registry from config.php

**URL:** <https://forum.getkirby.com/t/using-the-registry-from-config-php/5198>\
**Category:** Questions\
**Tags:** v2\
**Created:** [September 6, 2016, 9:47pm UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198 "2016-09-06T21:47:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AugustMiller](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/augustmiller/32/160_2.png) [@AugustMiller](https://forum.getkirby.com/u/AugustMiller)\
**Post date:** [September 6, 2016, 9:47pm UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/1 "2016-09-06T21:47:06Z")

</div>

I’m working on a couple of additions to my [Architect plugin](https://github.com/AugustMiller/kirby-architect), and had hoped to offer a few “optional extras” to developers, within the Readme.

Specifically, I want each person who uses the plugin to have all the basic functionality out of the box, and then be able to add a few [Page Methods](https://getkirby.com/docs/developer-guide/objects/page) by themselves. I’d prefer those extra methods not be baked in, because they might collide with field names and make bugs harder to track down.

Anyway, in `config.php`, I tried to use the Registry to set the following:

```php
kirby()->set('page::method', 'architect', function($page) {
  return Architect::blueprint($page->intendedTemplate());
});

```

This causes the method registry to blow up on [line 63](https://github.com/getkirby/kirby/blob/master/kirby/registry/method.php#L63), saying that the `page` class doesn’t exist, and therefore can’t be extended. Including this in a plugin works as expected.

Important: the legacy strategy for adding page methods also blows up, but (as expected) right in the config file. The `page` class is still not available.

```php
page::$methods['architect'] = function($page) {
  return Architect::blueprint($page->intendedTemplate());
};

```

Is there anything special about the way the `page` class is loaded that prevents it from being available in `config.php`, unlike other Registry options? I can set a route there, as expected.

Tips?

---

<div class="post-metadata">

**Author:** ![AugustMiller](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/augustmiller/32/160_2.png) [@AugustMiller](https://forum.getkirby.com/u/AugustMiller)\
**Post date:** [September 6, 2016, 9:58pm UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/2 "2016-09-06T21:58:23Z")

</div>

I think I may have come to a realization, independently…

It seems like these method-adding mechanisms have never been available within `config.php`, and I’d just imagined handling it this way.

Perhaps the Readme’s recommendation needs to be to add a second plugin file like `architect-customizations.php` and provide additional methods in there, as everything works swimmingly once inside the context of a plugin.

I’d interpreted “The best place to do this is in a plugin file: `/site/plugins/page-methods.php`” as an organizational suggestion, and not a statement about the limits of where core objects can be extended.

😉

---

<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:** [September 7, 2016, 6:33am UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/3 "2016-09-07T06:33:53Z")

</div>

How about this? Just an idea.

```php
kirby()->set('page::method', 'architect', function($page) {
  return Architect::blueprint(kirby()->page()->intendedTemplate());
});

```

---

<div class="post-metadata">

**Author:** ![fvsch](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fvsch/32/15908_2.png) [@fvsch](https://forum.getkirby.com/u/fvsch)\
**Post date:** [September 7, 2016, 6:57am UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/4 "2016-09-07T06:57:45Z")

</div>

I think the `Page` class is not loaded when Kirby includes the config files because, depending on your settings, it will have to load either the single-language or the multilang implementation of that class. Kirby loads a bunch of classes, including `PageAbstract`, but not the `Page` class at this point.

Solutions for what you want to do:

1. Do it in a file in `site/plugins`.
2. It might be possible to let users define a config entry and add to page methods in your plugin.

Second option may look like:

```php
c::set('architect.page.methods', [
  'architect' => function($page) {
    return Architect::blueprint($page->intendedTemplate());
  },
  'othermethod' => function($page) {
    …
  }
]);

```

But maybe that’s overly verbose and it would be better to introduce your users to how page methods can be registered, which is a skill they can apply for other needs.

---

<div class="post-metadata">

**Author:** ![jenstornell](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jenstornell/32/546_2.png) [@jenstornell](https://forum.getkirby.com/u/jenstornell)\
**Post date:** [September 7, 2016, 7:11am UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/5 "2016-09-07T07:11:36Z")

</div>

I don’t think the `$page` object or `page()` are loaded correctly as early as in the `config.php`?

I would add it as a plugin because of the way Kirby works. I’ve made a plugin myself that require an additional plugin for it to work:

[https://github.com/jenstornell/kirby-recaptcha](https://github.com/jenstornell/kirby-recaptcha)

> ```
> 2. Add your PHP callback as a plugin
> 
> ```

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [September 7, 2016, 7:38am UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/6 "2016-09-07T07:38:33Z")

</div>

What @fvsch wrote is correct. It’s not just the current `$page` that’s missing, but the whole `Page` class.  
Registering methods will only work from plugins, not from the `config.php`.

---

<div class="post-metadata">

**Author:** ![AugustMiller](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/augustmiller/32/160_2.png) [@AugustMiller](https://forum.getkirby.com/u/AugustMiller)\
**Post date:** [September 7, 2016, 4:16pm UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/7 "2016-09-07T16:16:38Z")

</div>

Very insightful answer— makes total sense.

Love this sentiment:

> …it would be better to introduce your users to how page methods can be registered, which is a skill they can apply for other needs.

🖖

---

<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, 4:55pm UTC](https://forum.getkirby.com/t/using-the-registry-from-config-php/5198/8 "2025-02-06T16:55:17Z")

</div>


