So, just something I was wondering..
Say I have a model called Comment
which has a function called get()
to fetch all the comments in the database. According to the "true MVC pattern", would it be allowed to call it directly in the view like this?
<html>
<?php foreach (Comment::get() as $comment): ?>
<h3><?= $comment->title ?></h3>
<?php endforeach; ?>
</html>
Or should you always pass an array of comments through the controller like this?
Controller:
return $view->assign('comments', Comment::get());
View
<html>
<?php foreach ($comments as $comment): ?>
<h3><?= $comment->title ?></h3>
<?php endforeach; ?>
</html>
I just find accessing the model functions directly in the view like the first example just more convenient sometimes. As far as I know, the view is still just taking care of the presentation bits and the model still does its job by getting those comments.. but I am not sure if it still is according to "MVC rules" :P