D
D
Denis Bondar2017-06-15 11:29:15
Yii
Denis Bondar, 2017-06-15 11:29:15

How to break a complex view into parts?

We have a view containing many different tables associated with different entities. For example: information about the client, as well as information related to it: contact details, purchased goods, comments, logs, technical support messages, mailing messages and other information related to this client. All of this is rendered by a single view file and contains many GridViews associated with different data providers.
We also have a fat controller that renders this view and generates a huge number of data providers and filter models for it, as a result of which a huge array of filter models and data providers is passed to the view.
In the view, each table is wrapped in pjax and, at first glance, there is no problem when filtering / sorting / paginating a separate table. But, in fact, it works out a thick controller action that forms a lot of queries to the database and instantiates a lot of models that are not needed for this one table.
How to properly split a view into parts?
There was an idea for each entity to allocate a separate controller that would allow interacting with this entity in isolation (add new contact data, delete old ones, update, display), and for each plate interacting with this controller, allocate its own view file. There must be a main controller that forms the main view skeleton within which these separate view files with labels are rendered. Something like this:

<div class="panel">
    <div class="panel-body">
        <div class="pjax">
            <?= $this->render('first_grid_view') ?>
        </div>
    </div>
</div>
<div class="panel">
    <div class="panel-body">
        <div class="pjax">
            <?= $this->render('second_grid_view') ?>
        </div>
    </div>
</div>
<div class="panel">
    <div class="panel-body">
        <div class="pjax">
            <?= $this->render('third_grid_view') ?>
        </div>
    </div>
</div>

What are the practices for implementing such complex interfaces without using front-end frameworks?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stanislav Tamat, 2017-06-15
@denisbondar

I didn’t quite understand the essence of the question, but maybe you should look here https://github.com/yiisoft/yii2/blob/master/docs/g...

D
dmitriy, 2017-06-15
@dmitriylanets

i solve by separating functionality into modules that contain: controller and template
call in php template do: <?=Module("module_name")?>
or in twig: {{module("module_name")}}

M
Maxim Fedorov, 2017-06-15
@qonand

And in what a problem to use the concept described by you? this is quite a normal variant ala HMVC

M
Maxim Timofeev, 2017-06-15
@webinar

Make a thin controller. And form data providers in the model. Essentially you have a user model and a bunch of relationships and methods in the model. At the same time, a thick model and a thin controller.
With view, everything is correct, break it into many views, so that the code is more readable. Some of these views may be more correctly designed not as a separate view, but as a widget, and maybe several of them can be combined into 1 custom widget.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question