- Getting Started
- Fundamentals
- Working with Forms
- Working with Databases
- Caching
- Extending Yii
- Testing
- Special Topics
Yii implements the model-view-controller (MVC) design pattern which is widely adopted in Web programming. MVC aims to separate business logic from user interface considerations so that developers can more easily change each part without affecting the other. In MVC, the model represents the information (the data) and the business rules; the view contains elements of the user interface such as text, form inputs; and the controller manages the communication between the model and the view.
Besides MVC, Yii also introduces a front-controller, called application, which represents the execution context of request processing. Application resolves the user request and dispatches it to an appropriate controller for further handling.
The following diagram shows the static structure of a Yii application:
Static structure of Yii application

The following diagram shows a typical workflow of a Yii application when it is handling a user request:
A typical workflow of Yii application

http://www.example.com/index.php?r=post/show&id=1
and the Web server handles the request by executing the bootstrap script index.php.request.urlManager. For this example, the controller
is post which refers to the PostController class; and the action is show
whose actual meaning is determined by the controller.show refers to a method named actionShow in the controller class. It then
creates and executes filters (e.g. access control, benchmarking) associated
with this action. The action is executed if it is allowed by the filters.Post model whose ID is 1 from the database.show with the Post model.Post model.@sapauljoseph
I don't think you understand what MVC is. MVC stands for model-view-controller. MVC is not a model. It simply means that your Yii app will mainly be written with models, views and controllers. Of course, it also has other things such a widgets, components and extensions.
Unless by "model" you mean the framework development pattern. Most php frameworks use MVC, but I think there is another type that runs on events. Never tried one, but since there are less frameworks of this type I assume it is not as good of a pattern.
@jonah
Thanks for pointing the typo. Yes, I meant MVC as an Architectural Pattern only. I know MVC is widely accepted but that doesn't mean it's the best out there right? And, I thought Yii runs on events also right? So, I don't think there is a separate architectural pattern that runs on events.
N-Tier is around for as long as I can remember and there are others like SOA and PAC.
Anyways, I still love Yii for it's very much similarity to the RoR and of course the eventual MVC...
Thanks for sharing your thoughts...
MVC is used so much because it simplified application development and maintenance by separating the application into 3 logical components; model (business logic), view (look and feel) and controller (the "glue").
This is obviously a very simplified description but basically the MVC pattern allows for organized and maintainable code.
Questions: - Filter is now run in the controller? - can give example of usage in filter?
It's very iconic how Yii is breaking things down here so perfectly. I've never seen a framework made so easy to understand or the MVC pattern in general. They're really on to something here. You can tell with all their language translations, etc.
great work guys! this is one of the best if not the best framework in the php framework djungle! i really appreciate your work!
I found yii better than other framework. It's easy to understand and on the other hand lite on CPU resources. Great work. keep it up
Is MVC the only model that is great? Isn't there some other better models? Why all Frameworks should use MVC only?