XF 2.1 Why does echo $visitor->Admin->last_login work but others don't?

Butteroll

Member
Currently working on an add-on. I've installed a column on the user table named btr_last_changed_custom_title, I've put a listener and everything.
But while

PHP:
$visitor = \XF::visitor();
echo $visitor->Admin->last_login;

work, this doesn't -

PHP:
$visitor = \XF::visitor();
echo $visitor->User->btr_last_changed_custom_title;

Gives me an error -

Code:
ErrorException: [E_USER_WARNING] Accessed unknown getter 'User' on XF:User[1] in src\XF\Mvc\Entity\Entity.php

And I did put up a listener for the User entity

PHP:
use XF\Mvc\Entity\Entity;

class Listener
{
    public static function userEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['btr_last_changed_custom_title'] = ['type' => Entity::INT, 'default' => 0];
        $structure->getters['btr_last_changed_custom_title'] = 'true';
    }
}

So why can't I pull this column?
 
The User entity is just \XF::visitor() itself, so you don't need to traverse a relation to access the column:

PHP:
$visitor = \XF::visitor();
echo $visitor->btr_last_changed_custom_title;
 
Back
Top Bottom