Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden model methods: how to know that they are reserved names? #2363

Open
3tlam opened this issue Aug 20, 2024 · 3 comments
Open

Hidden model methods: how to know that they are reserved names? #2363

3tlam opened this issue Aug 20, 2024 · 3 comments

Comments

@3tlam
Copy link
Contributor

3tlam commented Aug 20, 2024

Description

Hi all!

I think I ran into a bug with a field named inventory and accessing it in a page model.
The output is:

array(3) {
  ["children"]=>
  array(0) {
  }
  ["files"]=>
  array(0) {
  }
  ["template"]=>
  string(4) "home"
}

Expected behavior
Access to the field inventory, instead I think I get the result of $users->inventory()^, so a list of files

Additional context
Maybe this is expected behaviour, but as far as I could find in the docs, it should only be part of Kirby\Cms\User?

Thank you for all the hard work and the wonderful CMS!

To reproduce

# /site/blueprints/pages/default.yml
title: Default Page
type: page

fields:
  inventory:
    type: textarea
# /site/models/default.php
<?php

use Kirby\Cms\Page;

class DefaultPage extends Page
{
  public function myCustomMethod()
  {
    var_dump($this->inventory());
  }
}
# /site/templates/default.php
<?php $page->myCustomMethod() ?>

Your setup

K 4.3.0 Plainkit

@distantnative
Copy link
Member

There is also Page::inventory() as core method which is why you cannot use it as field name (or if you need to access it via $page->content()->get('inventory').

The problem is that the method is marked as internal (which is right as it shouldn't be used programatically by non-expert user), but that's also why it's hidden in the docs reference. Which then of course makes it hard for you to know that it's a reserved name.

@distantnative distantnative transferred this issue from getkirby/kirby Aug 20, 2024
@distantnative distantnative changed the title Field inventory collides in model with $user method Hidden model methods: how to know that they are reserved names? Aug 20, 2024
@3tlam
Copy link
Contributor Author

3tlam commented Aug 20, 2024

Heya

Thanks for the quick reply; yeah I was able to access it using content()

Given your explanation, I am now not sure if this works as expected or not - so feel free to close this :)

@distantnative
Copy link
Member

Totally expected in code, but a problem in our docs, which is why I moved this to our website repo so we find a solution for our docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants