G
G
gog692016-07-01 10:01:29
symfony
gog69, 2016-07-01 10:01:29

How to organize the following logic?

all guides write an example of how to make a blog
PostController
listAction
editAction
CommentsController
listAction
editAction
where to read how to do more complex things
let's say I have a header, post, comments and footer on the page if the
header and footer are put into controllers

{{ render(controller('headerController')) }}

{% block content %}{% endblock %}

{{ render(controller('footerController')) }}

I don’t understand the point then from this MVC if it’s almost the same flat-php
I want to do it like this:
PostControoller {
   indexAction() {

      .....

      return [
         "post" => $currentPostInfo,
         "comments" => $commentModel->getComments($id),
         "meta" => $helper->getItemsForHeaderAndFooter()
      ]

   }
}

or what is the best way to do it?
PS. header and footer are dynamically formed based on information from the database

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-07-01
Protko @Fesor

I don’t understand the point then from this MVC if it’s almost the same flat-php

Symfony request/response framework. MVC - web doesn't work that way. What is called MVC on the backend is actually mediating controller MVC or MVA.
Well, again, where is flat php? This is essentially the ability to do "under requests" and reuse the code. Some kind of widget.
If you don't need it, use template inheritance and put everything related to the formation of the footer and header of the site into the base one.
Do not get hung up on MVC, because people often lose, thinking that the model is doctrine entities and nothing more. And there are other services - this is also part of the model. And the whole point is in the division of responsibility (controllers convert HTTP requests into calls to model methods and convert model state into HTTP responses and nothing more).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question