XF 2.2 Set a getter?

Robert9

Well-known member
Yesterday I have learned how to manipulate $post->message.

Today I have learned how to add a getter to $post;

and now i found out:

to use the getter as a var like the table_fields with set and not only get, we use the cache.

add getter to structure:

$structure->getters['pager'] = ['getter' => 'getPager', 'cache' => true];

**getter => getPager is not neccessary, but i let it to remember that i can have other names also.


public function getPager()
{
return $this->_getterCache['pager'] ?? [];
}

public function setPager($var)
{
$this->_getterCache['pager'] = $var;
}


in my controller i can call get/set

and in my entity i can call set also from another function.

in my case:

=> setMessage(), if so set setPager()


and in my template have now a changed message and $post.pager with different integers with the information that i have changed the message.
 
Last edited:
Top Bottom