Answer the question
In order to leave comments, you need to log in
Sympfony2, what is the correct logic for storing and creating related objects?
The task is as follows:
There are several sites from which we must pull some data. The sites are all of the same subject, pulling up data is almost the same for everyone, but the processing is different.
The following implementation was proposed: an abstract class (AbstractSite) from which all others are inherited (Site1, Site2 ... SiteN). All data on sites should be stored on sites in one table with the fields Id, Name, URL (from which we will collect data) and slug (class name). In the abstract class, there are 2 methods getUrlData (getting the page by url) and getParceData (Which processes the page and writes it in a specific structure).
In the controller, we get all the site objects and call these 2 methods in a loop.
Everything would be fine, but the difficulty is that I have only known the symphony for a week and I don’t know how to implement it correctly. I know that there is a Superclass that fits our implementation, but I don’t know if the getRepository('AbstractSite')->findAll method will pull up an array with different classes.
I would be very grateful for help and constructive criticism.
Answer the question
In order to leave comments, you need to log in
Why store site data in a table?
If you need to store data in a table, then create a Site model (site table with your structure), then in the controller you will call
$sites = $this->getDoctrine()->getManager()->getRepository('MyBundle:Site')->findAll();
foreach ($sites as $site) {
$className = $site->getClassName();
$parser = new $className();
$parsedContent = parser->getParceData();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question