K
K
Ko12015-09-12 20:43:24
Laravel
Ko1, 2015-09-12 20:43:24

How to properly build architecture in MVC?

Let's say we have such a site - it has a top menu that changes after a page refresh. This menu is written in the main (master) view. So, in theory, so that the information in the menu is updated every time, every time in each controller (let it be a list of comments, even a list of friends) I will need to transfer this information, which is convenient, can I somehow get out? The project is being done on Laravel 5.1. And yet, there is one feature, the blade templating engine is not used (customer's requirement). I hope I explained clearly :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Elchev, 2015-09-13
@Ko1

For starters, blade is just a wrapper around php, and not using it gives you even more options than using it, although it doesn't look as pretty.
Then you have two options:
1) To do as DieZz said , view->share('key', 'value') it is best to register it in the controller from which all other controllers will then inherit.
2) Define a class for managing the menu and inject it into the view itself. Next is the option with a blade, how to do it without a blade, I hope you figure it out

@inject('metrics', 'App\Services\MetricsService')

<div>
    Monthly Revenue: {{ $metrics->monthlyRevenue() }}.
</div>

On the one hand, making injections in a view is not pretty, on the other hand, a template is not a view, it does not have its own controller. In short, a holivar theme, it's up to you.

D
Dmitry, 2016-01-20
@Astatroth

Composer to help you
Video (English)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question