Often, when writing widgets or editing Yii code, it is unclear whether or not the code is following the MVC pattern.
Here are a few suggestions to help detect the most obvious style errors.
The controller should contain code for collecting user input, retrieving models from the database, and rendering views.
In a controller there should never be:
Avoiding embedding field names allows you to change the database easily.
HTML code should only be in views.
Views should not contain:
The fewer PHP operations there are in the views, the better it is. Instead of concatenating two fields, it is better to write a getter method, so you can reuse it in other views.
Models are used for collecting user inputs, and accessing the database.
In models there should not be:
Widgets have a behaviour similar to controllers. If a widget is supposed to create a lot of HTML, it is better to create a view file for it.