Sorry, we don't support your browser.  Install a modern browser
This post is closed.

Ability to override Helper functions with aliases

This Nolt is piggybacking this archived Nolt:
https://kirby.nolt.io/369

Initially the wish was to be able to create an alias for go() to redirect(). The solution ended up being able to disable helper functions all together.

It is useful to be able to deactivate helper functions, but even better would be to be able to create an alias and still be able to use the function.

ie: instead of only being able to now say:

define('KIRBY_HELPER_GO', false);

being able to create an alias. Example:

define('KIRBY_HELPER_GO', 'redirect');

A lot of cookbook recipies uses go(), and its not intuitive how to solve the same need when go() is disabled.

2 years ago

Do you have an idea how we could implement that in PHP? Don’t think it’s possible to define functions with a dynamic name without trickery.

2 years ago

Sorry, but definitely beyond my PHP capabilities. Maybe I’m asking too much, but wanted to check if there were any options.

Maybe the problem is only really related to the “go()” function for now (at least from my googling around), and that an additional (duplicated) helper like redirect() could solve it?

Or even that both go() and redirect() are defined, and if go() is disabled, it has a fallback called redirect. Or even a safer fallback like kirbygo().

I don’t know. Just throwing out ideas.

2 years ago

Don’t think PHP supports this TBH, so I’m closing this. However you can solve it like this:

  1. Disable the core go() helper with the constant
  2. Copy over its definition into a plugin file or into index.php and name your version however you like.
2 years ago
1
Changed the status to
Archived
2 years ago

Thanks for taking the time looking at it, and I will try out that suggestion! :-)

2 years ago