XF 2.0 Can I add additional indexes to an Entity outside of the table columns?

Jaxel

Well-known member
I have my entity, it's values match the columns in my database.

I would like to add an additional index to my entity in code. This is not a calculated value, so its not something that could be returned by a getter. Its just a value I manually set in my code; to be called upon later.

How would I do this in the entity system?
 
Same way you would any other PHP object.

You have to create setter and getter methods, e.g.

PHP:
protected $foo = null;

public function setFoo($foo)
{
   $this->foo = $foo;
}

public function getFoo($foo)
{
   return $this->foo;
}

As accessing properties directly via $entity->foo; would only work if you added 'foo' => true to the list of getters, which you don't want to do, for some reason, even though it would work fine.

EDIT: I should however point out that $entity->foo = $foo; is unlikely to work, as setting properties is only meant to write to the structure, not custom methods. So you always have to use your setter.


Fillip
 
Dunno what to tell you then, if you look at \XF\Entity\Template you'll see it uses a property that isn't related to the DB. Inspect that file and see if there's anything they do different to you when setting that variable.


Fillip
 
Back
Top Bottom