Answer the question
In order to leave comments, you need to log in
How to correctly implement a calculated field for Entity (Symfony/Doctrine)?
Good afternoon. Mastering Symfony/Doctrine.
There is an entity User with a subdomain field :
class User
{
// ...
// тут значение домена третьего уровня
private $subdomain;
public function setSubdomain($subdomain)
{
$this->subdomain = $subdomain;
}
public function getSubdomain()
{
return $this->subdomain;
}
// ...
}
acme:
full_domain_template: http://{subdomain}.example.com
Answer the question
In order to leave comments, you need to log in
There are several solutions.
1) using a dirty hack to get the container and extract the necessary services and parameters from it. If you need to decide very quickly, then you can do it that way, but then do not forget to clean up after yourself when there is time for refactoring.
2) make a factory to create an entity (as you said)
These two options can be found in this question .
3) Pass the template through the method parameter:
class User
{
// ...
public function getFullDomain($template)
{
return str_replace("{subdomain}", $this->subdomain, $template);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question