V
V
Vadim2014-02-15 21:20:34
Design patterns
Vadim, 2014-02-15 21:20:34

How to correctly form data for a view in MVC?

It is more correct to form an array with data in the controller and pass it to the view, or you can transfer data to the view, and make the following logic in it:

foreach ($variable as $key => $value) {
            if ($value['status'] == 1) {
                echo "<li>".$value['name']."</li>";
            }
}

Or, in the controller, form an array that performs this selection by status.
And it will turn out in the view, here is the code:
foreach ($variable as $key => $value) {
    echo "<li>".$value['name']."</li>";     
}

And in general, it is desirable to prepare everything in the controller so that in the view you only need to insert it. Right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry S, 2014-02-15
@Hakkunamatata

It's certainly not the controller's job to do this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question