Is there a way to extend classes automatically created from the Doctrine2 database?
Example: I have this custom class created by Doctrine.
<?php
namespace Entities;
class User
{
private $id;
private $firstName;
private $lastName;
public function getId()
{
return $this->id;
}
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
public function getFirstName()
{
return $this->firstName;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
public function getLastName()
{
return $this->lastName;
}
I would like to add this function:
public function getFullName()
{
return $this->getFirstName().' '.$this->getLastname();
}
Is there a cleaner way than adding it directly to this class?
I tried to create another class (Test) in the libraries and extended it, and then add it to autoload (which works), but I get an error when I try to save the object:
class Test extends Entities\User {
public function getFullName() {
return $this->getFirstName().' '.$this->getLastname();
}
}
Message: The mapping file was not found with the name 'Test.dcm.yml' for the class 'Test'.
I am using Doctrine2 in CodeIgniter3.
Thank.
source
share