bnomei / kirby3-autoid

Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
https://forum.getkirby.com/t/kirby3-autoid-plugin/23572
MIT License
80 stars 8 forks source link

call on `null` #76

Closed S1SYPHOS closed 2 years ago

S1SYPHOS commented 2 years ago

Hey there, I got a structure field holding some values, and of course autoid as described in the wiki. From a select field (storing autoid as value), I select some stuff and get on with my life.

Now, inside a controller, calling this works:

# Fetch stuff from database
$stuff = autoid($page->stuff()->value);

# ...
echo $stuff->name()  # some-stuff

.. but inside model.php, this doesn't:

class StuffPage extends Page
{
    public function stuff()
    {
        $stuff = autoid($page->stuff()->value);
        return $stuff->name();
    }
}

.. instead it throws Call to a member function name() on null - I don't get it because when var_dumping the result, it's shown to be a StructureObject :confused:

S1SYPHOS commented 2 years ago

Well, I was just being a doofus, sorry ..