P
P
Pavel Busel2014-06-20 14:56:29
symfony
Pavel Busel, 2014-06-20 14:56:29

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

1 answer(s)
P
Pavel Solovyov, 2014-06-20
@pro100Coder

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();
}

And the abstract class from which other classes will be inherited has nothing to do with it. Since the model class for creating a table in the database is a completely different entity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question