I have an entity Paper which is connected to the paper table in my project.
In this entity, I have a field title.
The problem is that the field title can have some html tags inside and I need to make some query on this field. The queryes are without html tags.
My idea was to create an extra variable in my entity: title_without_html:
protected title_without_html;
/**
* Get title_without_html
*
* @return text
*/
public function getTitle_without_html()
{
return strip_tags($this->title);
}
And also in the constructor, I am creating the title_without_html.
Is this possible? If yes, how to do it properly. Actually, I am getting an error:
[Semantical Error] line 0, col 61 near ‘title_without_html’: Error: Class SciForum\Version2Bundle\Entity\Paper has no field or association named title_without_html
Your code miss a
$, and you should avoid not camelCase methods (for consistency with the Doctrine2 generated ones).Also, do not rely on the constructor: Doctrine2 do not call the constructor when fetching existing from the database.
This must work:
You don’t have to set a property for this instead you are calling this getter a lot of times (then, a property could be used for caching the result of
strip_tags).