• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Adding a field to the xf_user table

AndyB

Well-known member
#1
I added a field called most_likes_count to the xf_user table.

When I try to use this new field in a template like this:

1506994351274.png

I get the following error:

1506993950521.png

Do I need to extend the entity in order to use this new field in a template?
 

AndyB

Well-known member
#2
Yes I needed to extend the entit like this:

Listener.php
PHP:
<?php

namespace Andy\MostLikes\XF\Entity;

use XF\Mvc\Entity\Entity;

class Listener
{
    public static function userEntityStructure(\XF\Mvc\Entity\Manager $em, \XF\Mvc\Entity\Structure &$structure)
    {
        $structure->columns['most_likes_count'] = ['type' => Entity::UINT, 'default' => 0];
    } 
}
Code event listener:

1506997184100.png

Now I get this error:
 
Last edited: