Answer the question
In order to leave comments, you need to log in
Where to store the table name?
The question is purely about the design and architecture of the PHP application. There are options:
1) Do not store the name of the table anywhere and set it in queries, the disadvantages are clear
2) Store the name in a variable in the class, for example private $mysql_table = 'articles';
3) Take the name of the table from the class name, for example mine class ArticlesModel
, then 'articles'
this is the name of the table. Thus, I will lose the ability to access the database in controllers, because one controller can resolve actions for several similar entities and it will be forced to transfer processing to the model, and this is good, this imposes a strict restriction on the architecture.
But in the latter case, it is not clear how to deal with the situation when there are secondary tables. For example, an article has tags, respectively, AtriclesModel
andTagModel
but there is also an intermediate table that implements their relationship and it does not have its own class...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question