Answer the question
In order to leave comments, you need to log in
How to properly inherit and connect classes?
Guys, I can't figure it out.
I have three classes.
1) User (methods: create, update, delete) in mysql for users is a separate table.
2) Organization (methods: create, update, delete) in mysql for organizations is also a separate table.
3) Invoice (accounts) (methods: create, update, delete) in mysql for accounts a separate table, but contains id_user and id_org.
It turns out that my third Invoice class will crash if I rename some column in the tables users or organizations.
Did I select the entities incorrectly, or what is the reason?
Answer the question
In order to leave comments, you need to log in
Your Invoice should depend on User and Organization objects. Accordingly, inside Invoice you work with the parameters of the transferred objects.
$uid = $this->User->getId();
$oid = $this->Organisation->getId();
class Invoice
{
protected $User;
protected $Organisation;
public function __construct(User $User = null, Organisation $Organisation = null)
{
if (!is_null($User)) {
$this->setUser($User);
}
if (!is_null($Organisation)) {
$this->setOrganisation($Organisation);
}
}
public function setUser(User $User)
{
$this->User = $User;
}
public function setOrganisation(Organisation $Organisation)
{
$this->Organisation = $Organisation;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question