Hey, I have a registration form and I’m checking if a user exists before submitting the update function, but for some reason it doesn’t work, saying “Call to a member function exists() on null”, even tho the POST method does get the username.
This could be a bug or just some incomplete documentation:
The documentation of $user->exists() states that you can check, if a user exists, by the expression you used:
if($site->user('bastian')->exists())
The documentation of $site->user() is not quite precise about the return value, when searching by a username. It just says:
Fetching any user by username
<?php echo $site->user('bastian')->firstname() ?>
But the code of kirby/core/site.php clearly states, that null is returned, if the user does not exist. But this does not work with the $user->exists() method.
Edit: @texnixe, @lukasbestle : Do you know, which implementation is the “right” one? $site->user('some_username') returning null if the user does not exists – which makes the $user->exists() method irrelevant. Or should the constructor of the User class return a new object without a user file to make the exists() method work?
There is also this issue on github: https://github.com/getkirby/kirby/issues/458, but I think, that exact issue does not exist any more in the current code.
I didn’t even know that the docs mentioned the exists() method on the User object. I’ve been trusting on null for non-existing users since I’ve learned Kirby.