P
P
photosho2016-02-22 17:13:50
Laravel
photosho, 2016-02-22 17:13:50

Is it right to create a page structure with a controller?

Hello. An idea came up recently. Let's say the site has a complex structure with several kinds of pages and many repetitive elements. Would it be correct to build pages on such a site using a controller, as if by assembling them with a constructor - create views for repeating elements and then call them?
I'll explain a little. Suppose there is an article page on the site with a block of comments, and there is another page with a list of articles and displaying the latest comments on each element of this list. It would be logical to put the comments block in a separate display and call it on each page where comments need to be displayed, passing an array of comments to it.
Then the controller structure for each page, in a simplified form, will look like this:

...
$html .= veiw('...', [...]);
$html .= veiw('...', [...]);
$html .= veiw('...', [...]);
...

That is, again, it turns out something like a constructor. This way we avoid copying the code, but building the page falls on the shoulders of the controller. Is this correct and how, in general, is it customary to do this? Wouldn't this option load the server heavily with a large number of page displays?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
JhaoDa, 2016-02-22
@JhaoDa

That's right - read the documentation and use view composer 's (or view creators).

S
Stanislav Pochepko, 2016-02-22
@DJZT

Laravel uses inheritance patterns. Read what it is and you won't have to build a bike. And yes. View Composers will help you too, as JhaoDa said

M
Muhammad, 2016-02-22
@muhammad_97

Use @include

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question