Param() is empty in my panel field

Hello together!

Sry, maybe a stupid question, but I’m not able to get a $_GET param in my panel field. For my plugin, I need to show data depending on it. The url is as follows: http://localhost:8000/panel/site?tab=order&id=4

...
 Kirby::plugin('******', [
  'fields' => [
        'orderview' => [
          'computed' => [
            'id' => function() {
              $id = param('id');//get('id');
              return (string) $id;
            },
...

I tried param(), get() and other methods. Actually, the entire params() is empty. Appreciate your help on how to get my query $_GET param into my function here.

Greetings,
Jonas

As far as I currently understand it (I’m only 80% sure): The fields section is loaded asynchronously (like other sections) through its own API request. So the query you see in your browser in the Panel is not part of the request that runs when getting the fields (and executing this PHP part).

1 Like

I do not think the computed callback in PHP is aware of the context of the request. The docs only show how to access the field with $this.

you would have to add that logic to the computed props in the VUE component for your field.

1 Like

Hey, thank you both!
I was able to get the parameter in the vue file, thats true. But that actually doesn’t help me, since I need the GET param in the index.php because i want to do some DB select stuff with the get parameter. However, for the people in need, this is how you can get it inside the vue component itself:

Bla.vue file:

<script>
export default {
  props: {
    data: Array,
  },
  computed: {
    id:function () {
          const urlParams = new URLSearchParams(window.location.search);
          return urlParams.get('id');
        }
  }
}
</script>

what about getting the param in vue and making a API request to a custom endpoint to fetch the data you need?
you can find a similar example here: kirby3-fontselector/src/components/fields/FontFamily.vue at main · bnomei/kirby3-fontselector · GitHub
the font family field will use the api.get to fetch data from the backend on creation of the field.

2 Likes

Yes, that worked for me, thank you!