Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I'm using Yii for a few years and only right now I realized, that their demo application (empowered by CRUD auto-generation tool -- Gii) seems to be breaking key MVC architecture pattern. I'd like to discuss this here.

As long as I've been using MVC (about four years), I was always told, that view should not acquire data directly from model. Every piece of text about MVC, I've read so far, was always underlining, that both view and models should be completely separate and the controller is the only element, that spins them together. If I need any model data in view (most often used mechanism) I should let my controller to retrieve it and feed view with it.

Correct me, if I'm wrong, but finding this question and an answer to it makes me sure, that I'm right: while it is technically possible, it should be avoided.

So, in terms of Yii, that would be:

$probes = Probes::model()->getAllProbesForCurrentUser;

$this->render('index', array

(quite obvious, I think -- controller retrieves data from model and renders view, feeding it with that model)

If all above is right, then how should I explain this:

<?php $this->widget('CGridView', array
)); ?>

(a widget placed in view acquires data directly from model)

What am I missing?

share|improve this question
I have just realized, that I based my question on completely wrong assumption and therefore I made myself an complete idiot! :] –  trejder Jun 22 '14 at 13:20
This isn't a bad question and may help others who start out with a similar misconception. –  Bart van Ingen Schenau Jun 22 '14 at 13:41
@trejder - You're not the first to be tripped up by the many variants of MVC which includes MVP and MVVM. I voted to leave your question open as others are likely to make the same mistake in reviewing a sample. Running across this question may provide value to them so they can learn the nomenclature involved. –  GlenH7 Jun 22 '14 at 14:24

2 Answers 2

up vote 4 down vote accepted

The array can also called a ViewModel, it is different from the Model because it carries the data the view needs while the Model represent the application business entities. For simple CRUD form they are likely to be identical. But for complex form, a ViewModel can be combined from many models.

share|improve this answer
Thank you for your effort in trying to answer my question, however I have just realized, that I based my question on completely wrong assumption and therefore I made myself an complete idiot! :] Voting to close/delete my own question. –  trejder Jun 22 '14 at 13:19

This question is based on a completely wrong assumption. Of course, $model variable, used in widget, is retrieved by a controller and fed to view in as natural way as it can be in MVC world.

share|improve this answer
Dear ugly downvoter. Have enough courage to express any problems in this answer, that caused you to downvote it? –  trejder Sep 3 at 6:43
Sorry, maybe I shouldn't have downvoted you, but it bugs me you reduced MVC to "if the variable is from the controller then it's MVC"... yes, functionally is correct, but conceptually this way of thinking can lead to problems in the long run, just look around for the fat-controller/fat-model patterns and how people are trying to eliminate them in the MVC frameworks. It all comes down into really thinking and knowing what you are doing and how it could impact in the future. –  Nab Sep 9 at 21:47
@Nab I understand and agree with you, that I may have gone too far with simplifying the meaning or definition of MVC. But, this is not a forum, where we can discuss MVC. This is a Q&A site, where I put an answer to my own question to notify, that I misunderstood the basics and should not ask at all. –  trejder Sep 10 at 6:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.