You should be doing all your logic inside the controller. The view should only be used to output the data returned from your controller.
class Controller {
public function viewAction() {
$this->view->records = Model::find();
}
}
and in your view
{% foreach record in records %}
{{ record.id }}
{% endforeach %}
You will find it to be really hard to update your code if you start doing everything inside the view. Especially when you start splitting your views up into components.
Using model fetch in the view can easily lead to a poorly performing view without discipline.
I increased performance by moving business logic to the Model and fetch and transform to the Controller.
You should be doing all your logic inside the controller. The view should only be used to output the data returned from your controller.
class Controller {
public function viewAction() {
$this->view->records = Model::find();
}
}
and in your view
{% foreach record in records %}
{{ record.id }}
{% endforeach %}
You will find it to be really hard to update your code if you start doing everything inside the view. Especially when you start splitting your views up into components.