On Symfony2 with Doctrine2, Object = Entity?

Let's say I have a class User:

$user = new User(1);
$user->setName('Bob'); // save "bob" to database with ID 1
$user->setGender('Male'); // save "male" to database with ID 1

echo $user->getName(); // display bob
echo $user->getGender(); // display "male";

echo $user->getDesignation() // display "Mr. Bob"

Now, in Symfony2, with Doctrine2, it seems that Entitythis is the object that is used to create the database link. So I think that all the functions setName(), setGender(), getName()and getGender()must be within the file that is located in EntityBundle (because these functions UPDATE, or SELECT from the database).

But what about getDesignation()?

public function getDesignation() {
  if ($this->getGender() == 'Male') return "Mr. ".$this->getName();
  else return "Ms. ".$this->getName();
}

Is it possible to put a function that has absolutely no connection with the database in Entity? Is this not a bad practice?

+4
source share
2 answers

, ?

, . , "" , , ( ).

?

, - . .

+6

, , - , , Symfony , . , "mr". , :

public function getDesignation() {
  if ($this->getGender() == 'Male') return "Mr." else return "Ms.";
}

{{entity.designation | trans}}

, : ,

+1

All Articles