G
G
gog692016-09-14 23:39:36
symfony
gog69, 2016-09-14 23:39:36

Is a controller needed?

now I am writing a frontend for a certain system, the
router matches the url and directs everything to several controllers

function indexAction( $data )
{
    switch()
    {
          case 1:    return $this->render( [ "article" => [..], "events" => [ ..] ] );         
          case 2:    return $this->render( [ "article" => [..], "related_articles" => [ ..] ] );     
          case 3:    return $this->render( [ "folder" => [..], "child_articles" => [ ..] ] ); 
    }
}

Of course, the project does not have a switch, but a bunch of checks, determining the content type, determining the configuration, etc.
That is, this is the analysis of the request and the extraction of data (it's not just Post, as in all guides on frameworks, depending on the request, config, and several other factors that may appear later, article and events or articles and related_articles are retrieved, in addition to extracting data, data can be aggregated, etc.)
how to do it wisely?
I have an idea in my head to send all requests to a certain service that will do this analysis and return objects;
- simplePage
- twoColumnArticlePage
- twoColumnActiclePageWithEvents
- gridArticlePage
i.e. return $twoColumnActiclePageWithEvents->render();
all these classes are inherited from the base one into which to push twig
PS. this part of the application will only display the content. there will be no other routes pulling controllers

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question