User object within controller

i had an issue with kirby 2.4.0 where the $site->user() object was not valid within my controller but $site->users()->current() was. any idea how that could happen? i thought they would be the same?

i found out that the $site->users()->current() points to the first user not the current. how can that be?

return function($site, $pages, $page) {
    $userR = site()->user(); // using site() function
    echo 'panel login --> '.$userR->email().'<br>';
    $userC = $site->users()->current(); // using var $site
    echo 'why first user account ? --> '.$userC->email();
    return compact();

$site->user()->current() would return the currently logged in user, not `$site->users()->current().

i see. a typo. but why does $site->users()->current() not fail but return first user if function does not exists?

The users class inherits the current()method from the iterator class via the collection class. It just returns the current element of the array, but not the currently logged in user.

1 Like

ah. thx for explaining.